Published:2011/7/22 1:46:00 Author:Li xiao na From:SeekIC
by M. Conde de Almeida
Control software
The entire clock program was written in the PIC Assembly Language using the MPLAB Integrated Development Environment (v. 5.70.40) supplied free of charge by Microchip.
The source code and Hex files containing the program ready to be flashed into the PIC microcontroller can be obtained free of charge from the Publisher’s website, see "the Free Downloads’ inset. The file number is 030096-11. For those without access to a PIC programmer, the microcontroller is also available ready-programmed under number 030096-41.
The flowchart in Figure 2 summarizes the operation of the program. After an initialization routine where I/O pins, Interrupt register, Timer_0/Prescaler operation are configured and alarms information is read from the EEPROMs into the PIC data memory, the program enters a loop in which control keys are read and, based on their status, a specific branch is taken.
For example, if the Alarm Adjust key is pressed and held down longer than about 3 seconds, the program will execute the Alarm Adjust Routine and, once finished, return to the main loop.
If the Time Adjust key is held depressed for less than about 3 seconds, the display will show the current weekday. If the key remains pressed longer than about 3 seconds, the program will execute the Time Adjust routine and, once time and weekday are adjusted, return to the main loop.
When no key is pressed the program keeps updating the display, checking the current time against the alarm entries in memory and triggering the beeper if a matching times are found.
Although it has not indicated by flowchart, the display updating process is affected by the status of the PORTB.5 line (12 VDC supply monitor) while the alarm verification and triggering processes are subject to the status of Alarm On/Off and Snooze keys.
One important piece of the software is the time counting process. It is based on the microcontroller TIMER_0 which has the ability to interrupt the main program and deviate its execution to an interrupt handling routine whenever its count overflows (FFh -» OOh).
The microcontroller is configured so that the TIMER_0 overflow will take place every 2.048 ms. This is accomplished by setting the prescaler to divide the TIMER_0 clock by eight.
Whenever called, the interrupt handling routine, will increment a 16-bit counter. This counter has a maximum count of 29,297 (7271h). This means that every minute (29,297 x 2.048 ms = 60,000.256 ms or very close to one minute) it will overflow.
The overflow of the 16-bit counter increments the minute-counter (modulo-10) which, after overflowing, increments the tens-of-minutes counter (modulo-6) which increments the hour-counter and sure it will finally increment the tens-of-hours counter.
As shown above, the clock’s minute is slightly longer than it should be. This error, amounting to 0.000427%, will cause a time difference of less than two minutes per year which is pretty low compared to what is achieved by most the off-the-shelf clocks.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/07/22/Digital_Alarm_Clock___Based_on_a_PIC_micro__(3).html
Print this Page | Comments | Reading(3667)
Author:Ecco Reading(30197)
Author:Ecco Reading(3462)
Author:Ecco Reading(3182)
Author:Ecco Reading(3662)
Author:Ecco Reading(5233)
Author:Ecco Reading(3249)
Author:Ecco Reading(3390)
Author:Ecco Reading(3531)
Author:Ecco Reading(3936)
Author:Ecco Reading(3708)
Author:Ecco Reading(3678)
Author:Ecco Reading(3715)
Author:Ecco Reading(6029)
Author:Ecco Reading(3693)
Author:Ecco Reading(4479)