點陣顯示心型
心形圖案
#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 LedChar[] = { //點陣顯示字符轉換表
0xff,0x99,0x00,0x00,0x00,0x81,0xc3,0xe7//實心
//空心(0x99,0x66,0x7E,0x7E,0xBD,0xDB,0xE7,0xFF),case 7:需註釋
};
void main(){
EA=1;
ADDR3=0; //使能U4
ENLED=0;
TMOD=0x01; //使能T0為模式1
TH0=0xFC; // 為T0賦初始值
TL0=0x67;
ET0=1; //使能中斷
TR0=1; //開啟T0
while(1);
}
/**
中斷處理
*/
void InterRupt() interrupt 1{
static unsigned char i=0;
TH0=0xfc;
TL0=0x67;
P0=0xff;//清屏
switch(i){//點陣顯示循環圖案部分
case 0: ADDR2 = 0; ADDR1 = 0; ADDR0 = 0; i++; P0=LedChar[0]; break;
case 1: ADDR2 = 0; ADDR1 = 0; ADDR0 = 1; i++; P0=LedChar[1]; break;
case 2: ADDR2 = 0; ADDR1 = 1; ADDR0 = 0; i++; P0=LedChar[2]; break;
case 3: ADDR2 = 0; ADDR1 = 1; ADDR0 = 1; i++; P0=LedChar[3]; break;
case 4: ADDR2 = 1; ADDR1 = 0; ADDR0 = 0; i++; P0=LedChar[4]; break;
case 5: ADDR2 = 1; ADDR1 = 0; ADDR0 = 1; i++; P0=LedChar[5]; break;
case 6: ADDR2 = 1; ADDR1 = 1; ADDR0 = 0; i++; P0=LedChar[6]; break;
case 7: ADDR2 = 1; ADDR1 = 1; ADDR0 = 1; i=0; P0=LedChar[7]; break;
}
}
點陣顯示心型