新人初学写的程序。
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- #include<intrins.h>
- uchar code tab[] = {0x3F,0x06,0x5B,0x4f,
- 0x66,0x6D,0x7f,0x07,0x7F,
- 0x6F,0x77,0x7C,0x39,
- 0x5E,0x79,0x71};
- uchar code disp1[] = {1,2,3,4,5};
- uchar code disp2[] = {8,9,0xc,5,1};
- uchar code disp3[] = {0,0,0,0,0};
- sbit dout = P2^0;
- sbit clk = P2^1;
- void delayms(uint x);
- void sendonebety(uchar temp);
- void main(void)
- {
- uchar i;
- uchar temp;
- IT0 =1;
- EX0 =1;
- EA =1;
- while(1)
- {
- for( i = 0; i < 5;i ++)
- {
- temp = tab[disp1[i]];
- sendonebety(temp);
- }
- delayms(500);
- for( i = 0; i < 5;i ++)
- {
- temp = tab[disp2[i]];
- sendonebety(temp);
- }
- delayms(500);
- }
- }
- void sendonebety(uchar temp)
- {
- uchar j;
- for(j = 0; j < 8;j ++)
- {
- dout = 0;
- if(temp & 0x80)
- dout = 1;
- clk = 1;
- _nop_();
- clk = 0;
- _nop_();
- temp = temp << 1;
- }
- }
- void delayms(uint x)
- {
- uchar j;
- while(--x)
- {
- for(j = 0;j < 120;j ++);
- }
- }
- void int00(void) interrupt 0
- {
- uchar i,j;
- uchar temp;
- for( i = 0; i < 5;i ++)
- {
- for( i = 0; i < 5;i ++)
- {
- temp = tab[disp3[i]];
- sendonebety(temp);
- }
- delayms(1000);
- for( i = 0; i < 5;i ++)
- {
- temp = tab[disp3[i]];
- sendonebety(temp);
- }
- }
- delayms(2000);
- }
-
复制代码
全部资料下载地址:
实验五代码.doc
(20 KB, 下载次数: 6)
|