微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机驱动8*8LED点阵c程序

单片机驱动8*8LED点阵c程序

时间:11-29 来源:互联网 点击:
#include

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++;
}
}

仿真图:

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top