单片机AT89C52中led点阵显示数字C程序(连线方式)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
unsigned char codedigittab[18][8]={
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00}, //P
/*****************************************************************************************
**
*LED点阵实验(流动显示1 2 3 4 5 6 7 8 9)*
*说明通过P0和P2作为点阵接口*
*要求学员掌握LED点阵的工作原理和各点阵脚的定义及接法,具体接线请参考接线说明*
TL0=(65536-3000)%256;//定时器低位装载数据
if(cntb<18) //红色
{
P1=0xFF;
P2=tab[cnta];
P0=digittab[cntb][cnta];
}
else //绿色
{
P2=0xFF;
P1=tab[cnta];
P0=digittab[cntb-18][cnta];
*我们采用的LED点阵式是低功耗,在做实验时可以用单片机脚直接驱动*
******************************************************************************************/
#include<reg51.h>
unsigned char code tab[]={来自百度文库xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中
};
unsignedinttimecount;
unsigned charcnta;
unsigned charcntb;
void main(void)
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=1;//开启定时0
ET0=1;
EA=1;//开启中断
cntb=0;
while(1)
{ ;
{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00}, //R
{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00}, //E
{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00}, //C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H
}
}
/*************************************************
*
*定时中断
********************************************************/
void t0(void) interrupt 1 using 0
{
TH0=(65536-3000)/256;//定时器高位装载数据
}
if(++cnta>=8)cnta=0;
if(++timecount>=333)
{
timecount=0;
if(++cntb>=36)cntb=0;
}
}
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00}, //P
/*****************************************************************************************
**
*LED点阵实验(流动显示1 2 3 4 5 6 7 8 9)*
*说明通过P0和P2作为点阵接口*
*要求学员掌握LED点阵的工作原理和各点阵脚的定义及接法,具体接线请参考接线说明*
TL0=(65536-3000)%256;//定时器低位装载数据
if(cntb<18) //红色
{
P1=0xFF;
P2=tab[cnta];
P0=digittab[cntb][cnta];
}
else //绿色
{
P2=0xFF;
P1=tab[cnta];
P0=digittab[cntb-18][cnta];
*我们采用的LED点阵式是低功耗,在做实验时可以用单片机脚直接驱动*
******************************************************************************************/
#include<reg51.h>
unsigned char code tab[]={来自百度文库xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中
};
unsignedinttimecount;
unsigned charcnta;
unsigned charcntb;
void main(void)
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=1;//开启定时0
ET0=1;
EA=1;//开启中断
cntb=0;
while(1)
{ ;
{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00}, //R
{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00}, //E
{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00}, //C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H
}
}
/*************************************************
*
*定时中断
********************************************************/
void t0(void) interrupt 1 using 0
{
TH0=(65536-3000)/256;//定时器高位装载数据
}
if(++cnta>=8)cnta=0;
if(++timecount>=333)
{
timecount=0;
if(++cntb>=36)cntb=0;
}
}