赞
踩
数码管0~9循环显示
一个数码管是由a、b、c、d、e、f、g、dp八个二极管组成,八个LED一端接在一起,另一端引脚引出来。二极管如果阳极连在一起,就是共阳极数码管,阴极连在一起,就是共阴极数码管。
带小数点也就是dp点亮
1.共阴不带小数点0-F段码为:{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
2.共阳不带小数点0-F段码为:{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
3.共阴带小数点0-F段码为:{0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
4.共阳带小数点0-F段码为:{0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
- ORG 0000H;程序入口地址
- AJMP START;跳转到START程序
- ORG 0040H
-
- START:MOV DPTR, #TAB;建表将TAB所在的地址赋值给DPTR
- MOV R0, #0
- CPL P3.0;位选
- DISPLAY:
- MOV A,R0
- MOVC A,@A+DPTR;基地变址寻址
- MOV P2,A;显示
- LCALL DELAY
- INC R0
- CJNE R0,#10,DISPLAY;到10清零重新显示
- MOV R0, #0;
- LJMP DISPLAY
- SJMP $ ;在当前位置死循环
-
- DELAY:MOV R7,#250
- D1: MOV R6,#250
- D2: MOV R5,#8
- D3: DJNZ R5,D3
- DJNZ R6,D2
- DJNZ R7,D1
- RET
- TAB:
- DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH
- END
- #include <REGX52.H>
-
- unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,
-
- 0x6d,0x7d,0x07,0x7f,0x6f};
-
- void delay_ms(unsigned int ms)//ms延时函数
- {
- unsigned int i,j;
- for(i=ms;i>0;i--)
- for(j=110;j>0;j--);
-
- }
-
- void main()
- {
- P3_0=0;//位选
- while(1)
- {
- unsigned char i;
- for(i=0;i<10;i++)
- {
- P2=tab[i];//显示
- delay_ms(1000);
- }
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。