LED点阵程序

LED点阵程序,第1张

#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)

}

}

}

这个程序可以循环显示0~9.#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intuchar code Table_of_Digits[]={0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //00x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //10x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //20x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //30x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //40x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //50x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //60x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //70x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //80x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //90xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff}uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}uchar i=0,j=0,t=0,Num_Index,key,xi,yisbit we1=P1^1sbit we2=P1^3//主程序void main(){//P1=0x80Num_Index=0//从0 开始显示TMOD=0x01//T0 方式0TH0=(65536-2000)/256//2ms 定时TL0=(65536-2000)%256IE=0x82key=0xi=0yi=0EX0=1IT0=1TR0=1//启动T0while(1)}//T0 中断函数void ext_int0() interrupt 0{key++ key&=0x03}void LED_Screen_Display() interrupt 1{TH0=(65536-2000)/256//2ms 定时TL0=(65536-2000)%256switch(key){case 0: P0=0xffwe1=1P0=~Table_of_Digits[Num_Index*8+i]we1=0P0=0xff//输出位码和段码 we2=1P0=xdat[i]we2=0if(++i==8) i=0//每屏一个数字由8 个字节构成 if(++t==250) //每个数字刷新显示一段时间 { t=0if(++Num_Index==10) Num_Index=0//显示下一个数字 } breakcase 1: we1=1P0=~xdat[xi]we1=0we2=1P0=ydat[yi]we2=0if(++t==250) //每个数字刷新显示一段时间 { t=0yi++if(yi>7){yi=0xi++} if(xi>7)xi=0} breakcase 2: we1=1P0=0x00we1=0P0=0xff//输出位码和段码 we2=1P0=xdat[i]we2=0if(++t==250) //每个数字刷新显示一段时间 { if(++i==8) i=0//每屏一个数字由8 个字节构成 t=0} breakdefault:key=0 i=0 j=0 t=0 xi=0 yi=0 Num_Index=0 we1=1 P0=0xff we1=0 we2=1 P1=0x80 we2=0break}}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7900178.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存