Oxford English Dictionary gives it quite a long and decent history:
1845 Times 15 Sept. 8/3 Mr. King‥misstated the fact in saying that he had put a piece of lighted paper to the master's nose while asleep in that house; it was his hot pipe that he applied to the sleeper's nostrils, at the same time crying: Come, old chap, keep your pecker up.
1848 R. Morier Let. 8 Feb. in R. Wemyss Mem. & Lett. (1911) I. 65, I broke‥down completely
.‥ However, my pecker is up, and I have just put forward a motion in propria persona.
1873 Slang Dict., Pecker, ‘keep your Pecker up’,‥literally, keep your beak and head well up, ‘never say die’.
1875 W. S. Gilbert Trial by Jury 4 Be firm, my moral pecker.
1901 R. C. Lehmann Anni Fugaces 56 Weighed down by debt they yet keep up their pecker.
1928 A. Merritt Seven Footprints to Satan xiii. 180, I was talkin' loud to keep my pecker up.
1995 Time Out 9 Aug. 113/4 I've had my fill of trite wartime sentimentality and chirpy ‘keep yer pecker up’ dialogue.