> From: Matt Redmond[SMTP:mdredmond@CHARTER.NET] > Sent: Friday, September 26, 2003 4:32 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC:] General Program Strategy / Architecture > I'm just getting started PIC programming. I'm pretty > comfortable with programming but my hardware experience is > very limited. I'm reading as much as I can but thought > I'd solicit some advice from the list, so here goes: > My application will incorporate input from the user in the > form of button presses or IrDA communication. It (the > PIC) will also be talking to a realtime clock, RAM and one > or more serial peripherals. It will provide output to the > user in the form of flashes of one or more LEDs. > During all of this, the program needs to remain responsive > to both the user's button presses and to anything coming > in from the various peripherals. > I don't want my program locked up in tight delay loops > during things like flashing an LED - if that will affect > its responsiveness to input. > How do most of you deal with issues like this? The timing of the LEDs can be handled with timers inside of the PIC. If your chip has the timer compare function, you can set the compare register to the desired delay, start the timer, and then go off to do something else. If not, you can preset the timer so that after DELAY counts, it will overflow. In either case, the "end of delay event" can cause an interrupt to which the PIC can respond. The input events can likewise cause interrupts; they exist just for situations like this. They are tricky to program if you have not done so before, and not all PICs support them, but they are the best means to avoid wasting time waiting for something to happen. > Also - do any of you know of an IC that will do both of > the following: (1) Multiplex serial devices so I can use > the PICs single UART to communicate with multiple devices, > and (2) Buffer incoming data so I can check it at my > liesure? The data buffering can be done in the PIC by enabling interrupt on receive. After each character is received, the PIC would stop what it was doing, save the character in a buffer, then return to the background task. The buffer could be examined at any later time. This is a very typical use of interrupts. John Power -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.