单片机驱动8*8LED点阵c程序
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit acon=P1^0; //38译码器
sbit bcon=P1^1;
sbit ccon=P1^2;
sbit en=P1^7; //译码器使能
uint8 j=0,k=0;
uint16 i=0;
code uint8 ledcode[]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //
0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xC3,0xFF, // I
0xFF,0x99,0x66,0x7E,0xBD,0xDB,0xE7,0xFF, // 心
0xFF,0x99,0x99,0x99,0x99,0x99,0xC3,0xFF, // U
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }; // 哄老婆用
void timer1_init()
{
TMOD|=0x10;
TMOD&=0xef;
TH1=0xfc; //1ms
TL1=0x66;
TR1=1; //定时器1开启
}
void inter_init()
{
ET1=1; //定时器1中断开启
EA=1; //总中断开启
}
void frush()
{
switch(j)
{
case 0:acon=0;bcon=0;ccon=0;break; //扫描LED点阵
case 1:acon=1;bcon=0;ccon=0;break;
case 2:acon=0;bcon=1;ccon=0;break;
case 3:acon=1;bcon=1;ccon=0;break;
case 4:acon=0;bcon=0;ccon=1;break;
case 5:acon=1;bcon=0;ccon=1;break;
case 6:acon=0;bcon=1;ccon=1;break;
case 7:acon=1;bcon=1;ccon=1;break;
}
P2=ledcode[k+j]; //逐行输出
if(j==7)j=0;
j++;
}
main()
{
en=1;
P2=0xff;
timer1_init();
inter_init();
while(1);
}
void timer1_interrupt() interrupt 3
{
TH1=0xfc;
TL1=0x66;
i++;
frush();
if(i==500)
{
i=0;
if(k==32)k=0;
k++;
}
}
仿真图:
单片机驱动LED点 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)