仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<REG51.H>
- #include<intrins.h>
- typedef unsigned int uint16_t;
- typedef unsigned char uint8_t;
- uint8_t code seg_cc_table [] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c};//0-9
- uint8_t code dig_cc_table [] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
- uint16_t high = 0;
- uint16_t period = 0;
- sbit pulse = P3^2;
- uint8_t total_num[] = {0,0,0,0,0,0};
- void delay_ms(uint16_t xms)
- {
- uint16_t i = 0;
- uint8_t j = 0;
- for(i = 0; i < xms; i++)
- {
- for(j = 0; j < 75; j++)
- _nop_();
- }
- }
- void main()
- {
- uint16_t total =0;
- uint16_t i = 1;
- P2 = 0x00;
- P1 = 0x3f;
- TMOD = 0x09;
- TH0 = 0;
- TL0 = 0;
- ET0 = 1;
- EA = 1;
- while(pulse==1);
- TR0=1;
- while(pulse==0);
- while(pulse==1);
- TR0=0;
- while(1)
- {
- high = (uint16_t)TH0*256+TL0;
- total = high-1;
- total_num[0]= total %10;
- total_num[1]= total/10 %10;
- total_num[2]= total /100%10;
- total_num[3]= total /1000%10;
- total_num[4]= total /10000%10;
- total_num[5]= total /100000;
-
- for(i=0;i<6;i++)
- {
- P2 = dig_cc_table[i];
- P1 = seg_cc_table[total_num[i]];
- delay_ms(1);
- P1 = 0x00;
- }
- }
- }
复制代码
所有资料51hei提供下载:
简易波形发生器.7z
(1.05 MB, 下载次数: 30)
|