|
发表于 2013-2-18 10:18:33
|
显示全部楼层
一匹狼 发表于 2013-2-14 15:33 ![](static/image/common/back.gif)
数码管显示很乱,根本就没法读数,
我设计本意是显示6位,而数码管显示了8位
楼主,我写了个。在我的实验板上调试通了。
你把位选、段选定义改一下就好了。- /*
- *板极调试成功
- *6位数码管显示
- *
- */
- #include <reg52.h>
- sbit DuCs = P2^6;
- sbit WeCs = P2^7;
- #define DATA P0
- unsigned char Second = 0;
- unsigned char Minute =0;
- unsigned char Hour = 0;
- unsigned char Count = 0;
- unsigned char Scan = 0;
- unsigned char SMG_Buffer[8] = {0};
- unsigned char code TAB[] = {
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,
- 0x7d,0x07,0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71
- };
- unsigned char code WEI[]={
- 0xfe,0xfd,0xfb,0xf7,
- 0xef,0xdf,0xbf,0x7f};
- void Timer0_Init(void){
- TMOD=0x01;
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- ET0 = 1;
- TR0 = 1;
- }
- void Timer1_Init(void) {
- TMOD = 0x21;
- TH1 = (256 - 250);
- TL1 = (256 - 250);
-
- ET1 = 1; //打开定时器中断
- TR1 = 1; //开启定时器
- }
- void main(){
- Timer0_Init();
- Timer1_Init();
- EA = 1;
- while (1){
- SMG_Buffer[4] = Second /10;
- SMG_Buffer[5] = Second % 10;
-
-
- SMG_Buffer[2] = Minute / 10;
- SMG_Buffer[3] = Minute % 10;
- SMG_Buffer[0] = Hour / 10;
- SMG_Buffer[1] = Hour % 10;
- }
- }
- void Timer0_SRV(void) interrupt 1{
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- Second ++;
- if (100 == Second) {
- Second = 0;
- Minute ++;
- if (Minute == 60) {
- Minute = 0;
- Hour ++;
- if (Hour == 60){
- Hour =0;
- }
- }
-
- }
- }
- void Timer1_Service(void) interrupt 3{
- TH1 = (256 - 250);
- TL1 = (256 - 250);
- P0 = ~ (1 << Scan);
- WeCs = 1;
- WeCs = 0;
-
- P0 = TAB[SMG_Buffer[Scan]];
- DuCs = 1;
- DuCs = 0;
- Scan ++;
- if (Scan > 7){
- Scan = 0;
- }
- }
复制代码 |
|