51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > C51教程 > 详细内容
【吉林科技大学】第三章:89S51实践课题--点阵式LED“0-9”显示
发布时间:2009/6/16  阅读次数:1968  字体大小: 【】 【】【

Lesson 24

1. 实验任务
利用8X8点阵显示数字0到9的数字。
2. 电路原理图
  
3. 硬件系统连线
(1). 把“单片机系统”区域中的P1端口用8芯排芯连接到“点阵模块”区域中的“DR1-DR8”端口上;
(2).   把“单片机系统”区域中的P3端口用8芯排芯连接到“点阵模块”区域中的“DC1-DC8”端口上;
4. 程序设计内容
(1).   数字0-9点阵显示代码的形成
如下图所示,假设显示数字“0”
1 2 3     4 5  6   7   8
00 00   3E   41   41   41   3E 00
       因此,形成的列代码为 00H,00H,3EH,41H,41H,3EH,00H,00H;只要把这些代码分别送到相应的列线上面,即可实现“0”的数字显示。
送显示代码过程如下所示
       送第一列线代码到P3端口,同时置第一行线为“0”,其它行线为“1”,延时2ms左右,送第二列线代码到P3端口,同时置第二行线为“0”,其它行线为“1”,延时2ms左右,如此下去,直到送完最后一列代码,又从头开始送。
数字“1”代码建立如下图所示1 2 3     4 5  6   7   8
其显示代码为 00H,00H,00H,00H,21H,7FH,01H,00H
数字“2”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,27H,45H,45H,45H,39H,00H
数字“3”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,22H,49H,49H,49H,36H,00H
数字“4”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,0CH,14H,24H,7FH,04H,00H
数字“5”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,72H,51H,51H,51H,4EH,00H
数字“6”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,3EH,49H,49H,49H,26H,00H
数字“7”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,40H,40H,40H,4FH,70H,00H
数字“8”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,36H,49H,49H,49H,36H,00H
数字“9”代码建立如下图所示
1 2 3     4 5  6   7   8
00H,00H,32H,49H,49H,49H,3EH,00H
5. 汇编源程序
TIM                     EQU 30H
CNTA               EQU 31H
CNTB               EQU 32H
                                     ORG 00H
                                     LJMP START
                                     ORG 0BH
                                     LJMP T0X
                                     ORG 30H
START:           MOV TIM,#00H
                                     MOV CNTA,#00H
                                     MOV CNTB,#00H
                                     MOV TMOD,#01H
                                     MOV TH0,#(65536-4000)/256
                                     MOV TL0,#(65536-4000) MOD 256
                                     SETB TR0
                                     SETB ET0
                                     SETB EA
                                     SJMP $
T0X:
                                     MOV TH0,#(65536-4000)/256
                                     MOV TL0,#(65536-4000) MOD 256
                                     MOV DPTR,#TAB
                                     MOV A,CNTA
                                     MOVC A,@A+DPTR
                                     MOV P3,A
                                     MOV DPTR,#DIGIT
                                     MOV A,CNTB
                                     MOV B,#8
                                     MUL AB
                                     ADD A,CNTA
                                     MOVC A,@A+DPTR
                       MOV P1,A
                                     INC CNTA
                                     MOV A,CNTA
                                     CJNE A,#8,NEXT
                                     MOV CNTA,#00H
NEXT:             INC TIM
                                     MOV A,TIM
                                     CJNE A,#250,NEX
                                     MOV TIM,#00H
                                     INC CNTB
                                     MOV A,CNTB
                                     CJNE A,#10,NEX
                                     MOV CNTB,#00H
NEX:                 RETI                 
TAB:                                     DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
DIGIT:             DB 00H,00H,3EH,41H,41H,41H,3EH,00H
                                     DB 00H,00H,00H,00H,21H,7FH,01H,00H
                                     DB 00H,00H,27H,45H,45H,45H,39H,00H
                                     DB 00H,00H,22H,49H,49H,49H,36H,00H
                                     DB 00H,00H,0CH,14H,24H,7FH,04H,00H
                                     DB 00H,00H,72H,51H,51H,51H,4EH,00H
                                     DB 00H,00H,3EH,49H,49H,49H,26H,00H
                                     DB 00H,00H,40H,40H,40H,4FH,70H,00H
                                     DB 00H,00H,36H,49H,49H,49H,36H,00H
                                     DB 00H,00H,32H,49H,49H,49H,3EH,00H
                                     END
6. C语言源程序
#include <AT89X52.H>
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code digittab[10][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
                                                                       };
unsigned int timecount;
unsigned char cnta;
unsigned char cntb;
void main(void)
{
   TMOD=0x01;
   TH0=(65536-3000)/256;
   TL0=(65536-3000)%256;
   TR0=1;
   ET0=1;
   EA=1;
   while(1)
       {;
       }
}
void t0(void) interrupt 1 using 0
{
   TH0=(65536-3000)/256;
   TL0=(65536-3000)%256;
   P3=tab[cnta];
   P1=digittab[cntb][cnta];
   cnta++;
   if(cnta==8)
       {
           cnta=0;
       }
   timecount++;
   if(timecount==333)
       {
           timecount=0;
           cntb++;
           if(cntb==10)
               {
                   cntb=0;
               }
       }
}
  
我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号