#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define outdat P2
sbit ld=P3^0
sbit lw=P3^1
//数码管显示代码
unsigned char code tab[]={
0x01,0x02,0x03,0x04,0xFF,0xFF,0xFF,0xFF}
void delay1ms(unsigned int count) //延时1ms
{
unsigned char j
for(count>0count--)
for(j=0j<120j++)
}
void display(unsigned char num)
{
outdat=tab[num]
ld=0ld=1ld=0
outdat=0x01<<num
lw=0lw=1lw=0
delay1ms(2)
}
void main()
{
unsigned char i
while(1)
{
for(i=0i<8i++)
{
display(i)
}
}
}
点阵原理就是一个LED的两端都接IO,当正极为1,负极为0时点亮相应的LED。
下面是8×8的LED点阵程序,参考一下吧
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code TAB[]={
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0x00,0x82,0xFE,0x82,0x80,0xC0,0x00,0x00,
0x00,0x7C,0x82,0x82,0x82,0x7C,0x00,0x00,
0x02,0x0E,0x72,0x80,0x70,0x0E,0x02,0x00,
0x00,0x82,0xFE,0x92,0xBA,0x82,0xC6,0x00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00
}
/*delay(uint t)
{
uint a,b
for(a=0a<ta++)
for(b=0b<110b++)
} */
void main(void)
{
uint i,j,xx
uchar bittemp=0x01
while(1)
{
for(i=0i<40i++)
{
for(xx=0xx<500xx++)
{
bittemp=0x80
for(j=0j<8j++)
{
P2=0x00 //消隐
P0= ~TAB[i+8-j]
P2 = bittemp
bittemp >>= 1
}
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)