Playing (part 3)
Wheee! Things are starting to take shape on my little PIC project here
The code to control a character LCD is progressing nicely… it can now automatically align text on the screen and stuff like that. It’s also handling custom characters quite well. The nice thing with these screens is that you can display most ASCII characters on them, but also a number of customized characters (which are displayed by using the ASCII values that are normally non-printable characters, eg 0×00, 0×01, 0×02, etcetera).
Obviously, since I’m working in C the 0×00 one can be a bit of a problem at times, because in C it’s also the string termination character (but I can still send a 0×00 manually to the screen… so no big deal).
Also, in addition to powering the LCD, I also have a flashing LED once again! Only this time, it’s flashing at a pretty accurate 1 second interval, and is doing so using timers and interrupts. Once every 50 000 microseconds, an interrupt tells a variable to go up by one; once it reaches 25, we know that a second has passed
(If you’re wondering what the hell an interrupt is: when certain events happen, such as a timer reaching its maximum value or the state of a pin changing, that may generate an interrupt, at which point the processor jumps to a certain location in the program to handle it. Basically it’s calling the processor’s attention away from whatever it’s doing to handle something that is urgent and which probably should be handled right now. Afterwards it’ll get back to what it was doing before the interrupt happened. It’s like you’re walking in the grocery store and your phone rings: you stop to pick it up, and when you’re done you continue shopping. It’s the same principle really (you’re the processor, and your phone just generated an interrupt to get your attention to the fact that someone’s calling you). Your PC also does this, but you don’t notice it normally.)
That may seem a bit elaborate, and well, erm, it is elaborate, really. It takes a good amount of code, as well as a bunch of calculations to make sure that the timer runs properly. But I’m learning the PIC to tell what time it is, and I’m just using the flashing LED to make it indicate to me that a second has passed. For some reason that remains unexplained sprintf() doesn’t seem to be working (and it’s a bigass function too… you’ll probably never notice it on a PC, but on a PIC the size of it is significant), so it’s going to be difficult making it actually show the time. But I’ll find a way
Comments
Leave a Reply
