|
发表于 2011-7-13 02:37:30
|
显示全部楼层
本帖最后由 millwood 于 2011-7-13 02:42 编辑
in the above example, we used a 7segment led display.
what if you want to use a lcd display?
here is the code.- #include <regx51.h> //we use keil c51
- #include "gpio.h"
- #include "tmr0.h" //we use tmr0
- #include "rtc1.h" //we use tmr1
- #include "_7seg_lcd.h" //7 segment lcd, up to 4 char
- //hardware configuration
- //end hardware configuration
- void rtc2vRAM(void) {
- vRAM[0]=_rtc1.sec %10; //second
- vRAM[1]=_rtc1.sec / 10;
- vRAM[2]=_rtc1.min % 10; //minutes
- vRAM[3]=_rtc1.min / 10;
- }
- void mcu_init(void) {
- }
- int main(void) {
- mcu_init(); //reset the mcu
- _7seg_init(); //reset the 7segment display
-
- tmr0_init(1, TMR_10ms); //set tmr0 to trigger periodically
- tmr0_act(_7seg_display); //show the display
- rtc1_init(RTC_500ms); //tmr1 to act like a rtc
- rtc1_act(rtc2vRAM); //install rtc timer
- ei(); //enable global interrupt
- while (1) {
- }
- }
复制代码 look at how similar it is to the led version?
to the application code, it shouldn't matter how the actual display is done - as long as it is done.
that's the beautify of modular programming: you get to benefit from your prior investment in code.
|
|