|
发表于 2011-7-12 21:44:02
|
显示全部楼层
here is the 7segment related files:
_7seg.h- //_7seg led display driver
- //hardware configuration
- #define _7SEG_PORT P2 //7seg connection, active low
- #define _7SEG_DDR P2
- #define _7SEGs 0xff
- #define _7SEG_OFF(segs) {_7SEG_PORT= (segs);} //turn on segments, active low
- #define _7SEG_ON(segs) {_7SEG_PORT=~(segs);} //turn off segments
- #define DIG_PORT P3 //digits connection, active high
- #define DIG_DDR P3
- #define DIGs 0xff
- #define DIG_ON(digs) {DIG_PORT= (digs);} //turn on digs, active high
- #define DIG_OFF(digs) {DIG_PORT=~(digs);} //turn off digs
- #define _7SEG_NUMBER 8 //number of digits in the 7segment display
- //end hardware configuration
- extern unsigned char vRAM[8];
- //initialize the display
- void _7seg_init(void);
- //display the content of vRAM[8]
- void _7seg_display(void);
复制代码 _7seg.c- #include<regx51.h> //we use keil c51
- #include "gpio.h"
- #include "_7seg.h" //we use _7seg display
- //hardware configuration
- //end hardware configuration
- //global variable
- //display font
- unsigned char code _7seg_font[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};//???????
- //display buffer
- unsigned char vRAM[8]; //display buffer
- //initialize the display
- void _7seg_init(void) {
- _7SEG_OFF(_7SEGs); //clear leds - turn off all segments
- IO_OUT(_7SEG_DDR, _7SEGs); //leds as output
- DIG_OFF(DIGs); //all display off
- IO_OUT(DIG_DDR, DIGs); //all digit pins as output
- }
- //display the content of vRAM[8]
- void _7seg_display(void) {
- static unsigned char digit=0; //digit to be displayed
- DIG_OFF(DIGs); //turn all digits off
- _7SEG_ON(_7seg_font[vRAM[digit]]); //display the digit
- DIG_ON(1<<digit); //turn on the digit
- digit+=1; //increment the digit
- if (digit==_7SEG_NUMBER) digit=0; //reset the digit
- }
复制代码 |
|