我用数码管从0加到47循环,每次数字变化的时间和我程序设定的差别很远。跑完circle_disp()需要80多秒,即数字保持的时间应该是80多秒,而烧到板子上却是几秒的时间。好奇怪。数码管用的是共阴四位一体。请高手替我看看程序。
#include<reg52.h> #include<stdio.h> #define uint unsigned int #define uchar unsigned char sbit IR=P3^2;//红外接收端 sbit CODE=P3^3; sbit V_INT=P1^6; sbit CD4094_CLK=P2^7; //CD4094的时钟输入端 sbit CD4094_DATA=P2^6; //CD4094的数据输入端 sbit CD4094_STR1=P2^5; //控制数码管 sbit CD4094_STR2=P2^4; //控制PI3V514使能端 sbit sel_1=P2^0; //数码管片选端 sbit sel_2=P2^1; sbit sel_3=P2^2; sbit sel_4=P2^3; //数码管片选端 sbit beep=P1^1; uchar table[32]={0}; uint count[32]={0}; uchar button;//红外按键值 uint time_yindao; uint time_jieguo; uchar wei_two_flag; uchar wei_one_flag; static uchar chip_sel; code table_seg[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //0x88,0x83,0xc6,0xa1,0x86,0x84,0x82,0xc1};
void delay(uint x)//晶振为7.3728MHZ,0.283ms { uchar y; while(x--) { for(y=0;y<8;y++); } } /************模拟串口模式0,移位时钟程序****************/ SEND_CD4094(uchar temp_data) { uchar count=8; CD4094_CLK=0; do { if(temp_data&0x80) CD4094_DATA=1; else CD4094_DATA=0; CD4094_CLK=0; ; CD4094_CLK=1; temp_data=temp_data<<1; count--; } while(count);
} /*************数码管显示的控制************************/ PANNL_CHIP_DRIVER1(uchar REG_4094) { //EA=0; SEND_CD4094(REG_4094); CD4094_STR1=1; delay(1); CD4094_STR1=0; } /*************PI3V514使能端的控制*******/ PANNL_CHIP_DRIVER2(uchar REG_4094) { //EA=0; SEND_CD4094(REG_4094); CD4094_STR2=1; delay(1); CD4094_STR2=0; } void display(uchar segment) { PANNL_CHIP_DRIVER1(segment); delay(50); }
void circle_disp() //循环轮流选择芯片使能 { uint ii; for(ii=0;ii<2000;ii++) { PANNL_CHIP_DRIVER2(chip_sel); P2=0xfb; display(table_seg[chip_sel/10]);//十位 delay(100); P2=0xf7; display(table_seg[chip_sel%10]); //个位 delay(100); } chip_sel++; if(chip_sel==48) {chip_sel=0;} } void main() { while(1) { circle_disp(); } }
|