About four years ago, I fell all the way through that cycle. Luckily, I had an intrepid team of co-workers who helped me dig myself out of that hole. What's scary is that if it weren't for the random happening of Bell's Let's Talk Day, I may never even have shared these feelings in the first place. Thankfully I somehow developed the courage to speak up, and I'm forever grateful for the changes it imposed.
Since then, I've gotten better at noticing the patterns of this happening and have come up with ways which work for me to squelch the problem before it spirals out of control.
The first and most successful is of course, talking with peers. This was one of my primary motivators in joining Twitter, since it provided with me a theoretically limitless network of peers. I immediately began following some of my favourites, like @shanselman (btw if you don't know or follow Scott, do it right now, he's the best). If you're selective about who you follow and carry yourself appropriately, I've found tremendous value in the sense community from chin-wagging with peers.
My second tier support has always been time away from programming. Much like recovering from a workout, your brain needs time to rest. Our profession is all too accessible outside of the confines of "the office", after all you don't see doctor's going home and practicing on themselves or family members. Whenever I feel a tinge of this self-diminishing happening, I turn to some separation.
Thirdly, try learning something new. You'll probably strike out a few times, I know always do. But when you hit something that resonates with you, it'll reignite your love for the job and (hopefully) your happiness all over again.