单片机8x 8点阵程序,hc6800——es v2.0,显示字母和汉字

单片机8x 8点阵程序,hc6800——es v2.0,显示字母和汉字,第1张

//这里显示数字,字母的话,定义每个字母的代码就可以了,汉字够呛,16*16点阵还可以,8*8不是很好。

#include<reg51.h>

#include<intrins.h>

#define uchar unsigned char

#define uint unsigned int

uchar code Table_of_Digits[]=

{

0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0

0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1

0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2

0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3

0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4

0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5

0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6

0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7

0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8

0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //9

0xff,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,yi

//主程序

void main()

{

P1=0x80

Num_Index=0//从0 开始显示

TMOD=0x01//T0 方式0

TH0=(65536-2000)/256//2ms 定时

TL0=(65536-2000)%256

IE=0x82

key=0

xi=0

yi=0

EX0=1

IT0=1

TR0=1//启动T0

while(1)

}

//T0 中断函数

void ext_int0() interrupt 0

{

key++

key&=0x03

}

void LED_Screen_Display() interrupt 1

{

TH0=(65536-2000)/256//2ms 定时

TL0=(65536-2000)%256

switch(key)

{

case 0:

P0=0xff//输出位码和段码

P0=~Table_of_Digits[Num_Index*8+i]

P1=_crol_(P1,1)

if(++i==8) i=0//每屏一个数字由8 个字节构成

if(++t==250) //每个数字刷新显示一段时间

{

t=0

if(++Num_Index==10) Num_Index=0//显示下一个数字

}

break

case 1:

P0=~xdat[xi]

P1=0xff

P1=ydat[yi]

if(++t==250) //每个数字刷新显示一段时间

{

t=0

yi++

if(yi>7){yi=0xi++}

if(xi>7)xi=0

}

break

case 2:

P0=0xff//输出位码和段码

P0=~Table_of_Digits[80+j]

if(j==0)P1=0x80

P1=_crol_(P1,1)

if(++j==8) j=0//每屏一个数字由8 个字节构成

break

default:

key=0

i=0

j=0#include<reg51.h>

#include<intrins.h>

#define uchar unsigned char

#define uint unsigned int

uchar code Table_of_Digits[]=

{

0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0

0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1

0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2

0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3

0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4

0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5

0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6

0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7

0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8

0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //9

0xff,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,yi

//主程序

void main()

{

P1=0x80

Num_Index=0//从0 开始显示

TMOD=0x01//T0 方式0

TH0=(65536-2000)/256//2ms 定时

TL0=(65536-2000)%256

IE=0x82

key=0

xi=0

yi=0

EX0=1

IT0=1

TR0=1//启动T0

while(1)

}

//T0 中断函数

void ext_int0() interrupt 0

{

key++

key&=0x03

}

void LED_Screen_Display() interrupt 1

{

TH0=(65536-2000)/256//2ms 定时

TL0=(65536-2000)%256

switch(key)

{

case 0:

P0=0xff//输出位码和段码

P0=~Table_of_Digits[Num_Index*8+i]

P1=_crol_(P1,1)

if(++i==8) i=0//每屏一个数字由8 个字节构成

if(++t==250) //每个数字刷新显示一段时间

{

t=0

if(++Num_Index==10) Num_Index=0//显示下一个数字

}

break

case 1:

P0=~xdat[xi]

P1=0xff

P1=ydat[yi]

if(++t==250) //每个数字刷新显示一段时间

{

t=0

yi++

if(yi>7){yi=0xi++}

if(xi>7)xi=0

}

break

case 2:

P0=0xff//输出位码和段码

P0=~Table_of_Digits[80+j]

if(j==0)P1=0x80

P1=_crol_(P1,1)

if(++j==8) j=0//每屏一个数字由8 个字节构成

break

default:

key=0

i=0

j=0

t=0

xi=0

yi=0

Num_Index=0

P0=0xff

P1=0x80

break

}

}

t=0

xi=0

yi=0

Num_Index=0

P0=0xff

P1=0x80

break

}

}

#include <reg52.h>

sbit ADDR0 = P1^0

sbit ADDR1 = P1^1

sbit ADDR2 = P1^2

sbit ADDR3 = P1^3

sbit ENLED = P1^4

unsigned char code image[11][8] = {

{0xC3, 0x81, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3}, //数字0

{0xEF, 0xE7, 0xE3, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3}, //数字1

{0xC3, 0x81, 0x9D, 0x87, 0xC3, 0xF9, 0xC1, 0x81}, //数字2

{0xC3, 0x81, 0x9D, 0xC7, 0xC7, 0x9D, 0x81, 0xC3}, //数字3

{0xCF, 0xC7, 0xC3, 0xC9, 0xC9, 0x81, 0xCF, 0xCF}, //数字4

{0x81, 0xC1, 0xF9, 0xC3, 0x87, 0x9D, 0x81, 0xC3}, //数字5

{0xC3, 0x81, 0xF9, 0xC1, 0x81, 0x99, 0x81, 0xC3}, //数字6

{0x81, 0x81, 0x9F, 0xCF, 0xCF, 0xE7, 0xE7, 0xE7}, //数字7

{0xC3, 0x81, 0x99, 0xC3, 0xC3, 0x99, 0x81, 0xC3}, //数字8

{0xC3, 0x81, 0x99, 0x81, 0x83, 0x9F, 0x83, 0xC1}, //数字9

{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //全亮

}

void main()

{

EA = 1 //使能总中断

ENLED = 0 //使能U4,选择LED点阵

ADDR3 = 0

TMOD = 0x01 //设置T0为模式1

TH0 = 0xFC //为T0赋初值0xFC67,定时1ms

TL0 = 0x67

ET0 = 1//使能T0中断

TR0 = 1//启动T0

while (1)

}

/* 定时器0中断服务函数 */

void InterruptTimer0() interrupt 1

{

static unsigned char i = 0 //动态扫描的索引

static unsigned int tmr = 0 //1s软件定时器

static unsigned char index = 9 //图片刷新索引

TH0 = 0xFC //重新加载初值

TL0 = 0x67

//以下代码完成LED点阵动态扫描刷新

P0 = 0xFF //显示消隐

switch (i)

{

case 0: ADDR2=0ADDR1=0ADDR0=0i++P0=image[index][0]break

case 1: ADDR2=0ADDR1=0ADDR0=1i++P0=image[index][1]break

case 2: ADDR2=0ADDR1=1ADDR0=0i++P0=image[index][2]break

case 3: ADDR2=0ADDR1=1ADDR0=1i++P0=image[index][3]break

case 4: ADDR2=1ADDR1=0ADDR0=0i++P0=image[index][4]break

case 5: ADDR2=1ADDR1=0ADDR0=1i++P0=image[index][5]break

case 6: ADDR2=1ADDR1=1ADDR0=0i++P0=image[index][6]break

case 7: ADDR2=1ADDR1=1ADDR0=1i=0P0=image[index][7]break

default: break

}

//以下代码完成每秒改变一帧图像

tmr++

if (tmr >= 1000) //达到1000ms时改变一次图片索引

{

tmr = 0

if (index == 0) //图片索引10~0循环

index = 10

else

index--

}

}


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存