8.3. led matrix_Ngat ngoai_COM
//+===Chuong trinh LED matrix display===========+
//| Thiet ke: Nguyen Chi Linh - DT8K47 - DHBKHN |
//| MCU: PIC16F88 (4K FLASH ROM, 256K EEPROM) |
//| Cac IC khac: 74154 - demux/decoder 1-of-16 |
//| 74595 - Ghi dich 8bit |
//+=============================================+
#include <16f88.h>
#include
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9) //Baud_min=4800 Baud_max=115200
#include
#include //File chua bo font ma hoa ky tu ASCII
// Dinh nghia cac chan cho ket noi 74595
#bit clk = 0x06.1 //RB0
#bit data = 0x06.3 //RB1
#bit latch = 0x06.4 //RB3
// Bo nho dem man hinh hien thi
int8 buff_disp[17]; //Bo nho dem cho man hinh LED
int8 max_char=117; //SO ky tu hien thi toi da
int8 time=5; //Bien quy dinh toc do chu chay
int1 text_eeprom=0;
int8 chon=0;
int8 address;
int8 choose_text;
//=========KHAI BAO CAC CHUONH TRINH CON================
int8 doc_eeprom(int8 addr);
void send_2_595(int8 temp);
void display();
void copy_2_ram1(int8 index_char);
void copy_2_ram2(int8 index_char);
void update_eeprom();
void convert_bcd(int8 x);
//=============================================
#INT_EXT
EXT_ISR() {
disable_interrupts(GLOBAL);
clear_interrupt(int_ext);
chon++;
if(chon==3) chon = 0;
if (RB7 == 0) RB7=1;
else RB7 = 0;
choose_text = 0;
enable_interrupts(GLOBAL);
}
//===========Chuong trinh chinh================
void main() {
int8 i,j,k;
#bit update_rom = 0x06.6
char const a[119]= " Hello World.LED Matrix PIC16F88 - 74154 - 74595. Bang thong tin dien tu.Nguyen Chi Linh-DT8 DAI HOC BACH KHOA HA NOI ";
char const b[119]= " HAPPY NEW YEAR *2006* - CHUC MUNG NAM MOI - Chuc Mung Nam Moi - Happy new year. linhnc308@yahoo.com 1234567890 ";
char const c[119]= " You like a little flame in my heart. When I see you, the flame is like up. Because I love you. Because I LOVE YOU ";
char const adc[6] = " ADC=";
//===========================================
TRISA=0x10; // Thiet lap chan vao ra
TRISB=0b00100101;
//==Thiet lap ngat ngoai 0 ==================
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
//===========================================
setup_adc_ports(sAN4); //Chon kenh AN4 nhung ko hieu sao can them phan khai bao
setup_adc(ADC_CLOCK_INTERNAL);// ben duoi dechon dung kenh AN4 cho no chay dung
//Chon kenh AN4 clear cac bit tai thang ghi ADCON1 (chs0 : 2)
chs0=0; //Clear bit 1f.3
chs1=0; //Clear bit 1f.4
chs2=1; //Clear bit 1f.5
delay_ms(10);
//===========================================
for(i=0;i<6;++i)
write_eeprom(0xf0+i,adc[i]);
for(i=0;i<117;++i)
write_eeprom(i,a[i]);
write_eeprom(0xff,max_char); // Luu so ky tu toi da vao ROM
if(update_rom==1) //Kiem tra cong tac cap nhat du lieu
update_eeprom(); //Goi chuong trinh con cap nhat(giao tiep qua cong COM)
hien_thi:
for (i=0;i<=16;i++) // Clear RAM of buff_disp
buff_disp[i]=0xff;
//Doan chuong trinh nay se hien thi noi dung ban tin luu trong EEPROM
address = label_address(hien_thi);
i=0;j=0;
while(1){
TRISB0 = 1;
for (i=0;i<=max_char;i++) // Begin of text
{
if(choose_text==0) {choose_text=1; goto hien_thi;}
if(text_EEPROM==0)
{
switch(chon)
{
case 0: j=a[i]-32; break;
case 1: j=b[i]-32; break;
case 2: j=c[i]-32; break;
case 3: chon=0; break;
}
}
else
j=read_eeprom(i)-32;
if(j < 51)
copy_2_ram1(j);
else
{
j=j-51;
copy_2_ram2(j);
}
}
k=read_adc();
convert_bcd(k);
for(i=0;i<8;++i)
{
k = doc_eeprom(0xf0 + i)-32;
copy_2_ram1(k);
}
}
}
//========= END MAIN ==============
// === CAC CHUONG TRINH CON =========
//=======Gui du lieu theo duong noi tiep toi 595============
void send_2_595(int8 temp) {
#bit flag_bit = temp.7 // bien temp la du lieu 8-bit can gui
int8 i;
clk=0;
for(i=0;i<8;i++)
{
if(flag_bit)
data=1; //bit 1
else data=0; //bit 0
clk=1;
clk=0;
temp<<=1; // Dich trai 1 bit
}
latch=1; //Chot du lieu
latch=0;
}
//===========Chuong trinh con hien thi=========
void display() {
int8 count,column_count;
int8 i;
time = read_adc()/10; // Viec doc gia tri ADC truoc khi hien thi lam cho viec thay doi
// toc do chu chay linh hoat hon, truc tiep tha doi
for (i=0;i<=time;i++) //Toc do chu chay thay doi boi bien time
{
column_count=0; //Bien dem so cot, xem da quet het 16 cot chua
for(count=16;count>0;count--)
{
send_2_595(buff_disp[count]);
PORTA=column_count;
delay_us(500);
column_count++;
}
}
}
//========Copy to Ram1=====================
void copy_2_ram1(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
buff_disp[i]= buff_disp[i-1]; // Dich RAM sang trai
buff_disp[0]= font[index_char].b[j]; // Luu ma ascii vao RAM
display(); // Goi hien thi
}
buff_disp[0]=0xff;
}
//========Copy to Ram 2===================
void copy_2_ram2(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{
for (i=16;i>0;i--) // Dich RAM
buff_disp[i]= buff_disp[i-1]; //Dich RAM sang trai
buff_disp[0]=font2[index_char].b[j]; //Luu ma ascii vao RAM
display(); // Goi hien thi
}
buff_disp[0]=0xff; // Them mot khoang trang giua hai ky tu
}
//=========Update EEPROM===================
void update_eeprom() {
byte i,j,addr,max;
char temp;
char string[64];
// Hien thi noi dung cua EEPROM
printf("\r\n256 byte EEPROM of PIC16F88:\r\n"); // Display contents of the first 64
for(i=0; i<=15; ++i) // bytes of the data EEPROM in hex
{
for(j=0; j<=15; ++j)
printf( "%2x ", doc_eeprom( i*16+j ) );
printf("\n\r");
}
// Hien thi noi dung ban tin
i=0;
do
{
temp = doc_eeprom(i);
printf( "%C", temp);
i++;
} while (temp != 0xff);
//--------Ket thuc ----------
printf("\r\nTong so chu: %2u", doc_eeprom(0xff));
printf("\r\n\nCo thay doi ban tin ko(Y/N)? "); temp=getc();//temp = getc();
if (temp == 'y' || temp == 'Y')
{
printf("\r\nSo chu hien thi moi la: ");
max_char=gethex();
write_eeprom(0xff,max_char);
printf("\r\nDia chi EEPROM can thay doi: ");
addr = gethex();
if (addr >= max_char)
write_eeprom(0xff,addr);
printf("\r\nSo ky tu them vao: ");
max = gethex(); // Tra ve gia tri Hexa
if(max >= max_char)
write_eeprom(0xff,max); // Cap nhat so ky tu
printf("\r\nNew: ");
get_string(string,max+1);
for (i=0;i
{
write_eeprom(addr,string[i]);
addr=addr+1;
}
text_eeprom=1;
}
else
{
printf("Tro ve !"); // Ket thuc viec cap nhat, tro ve hien thi
text_eeprom = 0;
}
}
//=============READ EEPROM=====================
int8 doc_eeprom(int8 addr)
{
EEADR=addr;
RD=1;
return(EEDATA);
}
//=======Chuyen gia tri hex ra so ASCII=========
void convert_bcd(int8 x)
{
int8 temp;
int8 a;
temp=x%10; //chia lay phan du, so hang don vi
write_eeprom(0xf7,temp+0x30); //Cong them 0x30 de tra ve gia tri SCII
a=x/10; //tach hang tram va hang chuc
temp=a%10; //tach so hang chuc
write_eeprom(0xf6,temp+0x30);
temp=x/100;
write_eeprom(0xf5,temp+0x30);
}
8.4. led matrix ket noi RS232
//+===Chuong trinh LED matrix display===========+
//| Thiet ke: Nguyen Chi Linh - DT8K47 - DHBKHN |
//| MCU: PIC16F88 (4K FLASH ROM, 256K EEPROM) |
//| Cac IC khac: 74154 - demux/decoder 1-of-16 |
//| 74595 - Ghi dich 8bit |
//+=============================================+
#include <16f88.h>
#include
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9) //Baud_min=4800 Baud_max=115200
#include
#include //File chua bo font ma hoa ky tu ASCII
// Dinh nghia cac chan cho ket noi 74595
#bit data = 0x06.1 //RB1
#bit clk = 0x06.0 //RB0
#bit latch = 0x06.3 //RB3
// Bo nho dem man hinh hien thi
int8 buff_disp[17]; //Bo nho dem cho man hinh LED
int8 max_char=117; //SO ky tu hien thi toi da
int8 time=5; //Bien quy dinh toc do chu chay
//=========KHAI BAO CAC CHUONH TRINH CON================
int8 doc_eeprom(int8 addr);
void send_2_595(int8 temp);
void display();
void copy_2_ram1(int8 index_char);
void copy_2_ram2(int8 index_char);
void update_eeprom();
void convert_bcd(int8 x);
//=============================================
//===========Chuong trinh chinh================
void main() {
int8 i,j;
#bit update_flag = 0x06.4
char const a[119]= " Hello Wolrd.LED Matrix PIC16F88 - 74154 - 74595. Bang thong tin dien tu.Nguyen Chi Linh-DT8 DAI HOC BACH KHOA HA NOI ";// Ky tu NULL duoc them vao cuoi
char const adc[6] = " ADC="; 1
//===========================================
TRISA=0x10; // Thiet lap chan vao ra
TRISB=0b00100100;
setup_adc_ports(sAN4); //Chon kenh AN4 nhung ko hieu sao can them phan khai bao
setup_adc(ADC_CLOCK_INTERNAL);// ben duoi dechon dung kenh AN4 cho no chay dung
//Chon kenh AN4 clear cac bit tai thang ghi ADCON1 (chs0 : 2)
chs0=0; //Clear bit 1f.3
chs1=0; //Clear bit 1f.4
chs2=1; //Clear bit 1f.5
delay_ms(10);
//===========================================
for(i=0;i<6;++i)
write_eeprom(0xf0+i,adc[i]);
for(i=0;i<117;++i)
write_eeprom(i,a[i]);
write_eeprom(0xff,max_char); // Luu so ky tu toi da vao ROM
//=======BEGIN DISPLAY FUNCTION==============
//Doanchuong trinh nay se hien thi noi dung ban tin luu trong EEPROM
while(1){
for (i=0;i<=16;i++) // Clear RAM of buff_disp
buff_disp[i]=0xff;
if(update_flag==1) //Kiem tra cong tac cap nhat du lieu
update_eeprom(); //Goi chuong trinh con cap nhat(giao tiep qua cong COM)
// time = read_adc()/10; //Cap nhat bien quy dinh toc do chu chay tren man hinh
for (i=0;i<=max_char;i++) // Begin of text
{
j=read_eeprom(i)-32; //Lay gia tri ASCII cua ky tu
//if(j==51) copy_2_ram1(51);
if(j < 51)
copy_2_ram1(j);
else
{
j=j-51;
copy_2_ram2(j);
}
}
j=read_adc();
convert_bcd(j);
for(i=0;i<8;++i)
{
j = doc_eeprom(0xf0 + i)-32;
copy_2_ram1(j);
}
}
}
//========= END MAIN ==============
// === CAC CHUONG TRINH CON =========
//=======Gui du lieu theo duong noi tiep toi 595============
void send_2_595(int8 temp) {
#bit flag_bit = temp.7 // bien temp la du lieu 8-bit can gui
int8 i;
clk=0;
for(i=0;i<8;i++)
{
if(flag_bit)
data=1; //bit 1
else data=0; //bit 0
clk=1;
clk=0;
temp<<=1; // Dich trai 1 bit
}
latch=1; //Chot du lieu
latch=0;
}
//===========Chuong trinh con hien thi=========
void display() {
int8 count,column_count;
int8 i;
time = read_adc()/10; // Viec doc gia tri ADC truoc khi hien thi lam cho viec thay doi
// toc do chu chay linh hoat hon, truc tiep tha doi
for (i=0;i<=time;i++) //Toc do chu chay thay doi boi bien time
{
column_count=0; //Bien dem so cot, xem da quet het 16 cot chua
for(count=16;count>0;count--)
{
send_2_595(buff_disp[count]);
PORTA=column_count;
delay_ms(1);
column_count++;
}
}
}
//========Copy to Ram1=====================
void copy_2_ram1(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
buff_disp[i]= buff_disp[i-1]; // Dich RAM sang trai
buff_disp[0]= font[index_char].b[j]; // Luu ma ascii vao RAM
display(); // Goi hien thi
}
buff_disp[0]=0xff;
}
//========Copy to Ram 2===================
void copy_2_ram2(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{
for (i=16;i>0;i--) // Dich RAM
buff_disp[i]= buff_disp[i-1]; //Dich RAM sang trai
buff_disp[0]=font2[index_char].b[j]; //Luu ma ascii vao RAM
display(); // Goi hien thi
}
buff_disp[0]=0xff; // Them mot khoang trang giua hai ky tu
}
//=========Update EEPROM===================
void update_eeprom() {
byte i,j,addr,max;
char temp;
char string[64];
// Hien thi noi dung cua EEPROM
printf("\r\n256 byte EEPROM of PIC16F88:\r\n"); // Display contents of the first 64
for(i=0; i<=15; ++i) // bytes of the data EEPROM in hex
{
for(j=0; j<=15; ++j)
printf( "%2x ", doc_eeprom( i*16+j ) );
printf("\n\r");
}
// Hien thi noi dung ban tin
i=0;
do
{
temp = doc_eeprom(i);
printf( "%C", temp);
i++;
} while (temp != 0xff);
//--------Ket thuc ----------
printf("\r\nTong so chu: %2u", doc_eeprom(0xff));
printf("\r\n\nCo thay doi ban tin ko(Y/N)? "); temp=getc();//temp = getc();
if (temp == 'y' || temp == 'Y')
{
printf("\r\nSo chu hien thi moi la: ");
max_char=gethex();
write_eeprom(0xff,max_char);
printf("\r\nDia chi EEPROM can thay doi: ");
addr = gethex();
if (addr >= max_char)
write_eeprom(0xff,addr);
printf("\r\nSo ky tu them vao: ");
max = gethex(); // Tra ve gia tri Hexa
if(max >= max_char)
write_eeprom(0xff,max); // Cap nhat so ky tu
printf("\r\nNew: ");
get_string(string,max+1);
for (i=0;i
{
write_eeprom(addr,string[i]);
addr=addr+1;
}
}
else printf("Tro ve !"); // Ket thuc viec cap nhat, tro ve hien thi
}
//=============READ EEPROM=====================
int8 doc_eeprom(int8 addr)
{
EEADR=addr;
RD=1;
return(EEDATA);
}
//=======Chuyen gia tri hex ra so ASCII=========
void convert_bcd(int8 x)
{
int8 temp;
int8 a;
temp=x%10; //chia lay phan du, so hang don vi
write_eeprom(0xf7,temp+0x30); //Cong them 0x30 de tra ve gia tri SCII
a=x/10; //tach hang tram va hang chuc
temp=a%10; //tach so hang chuc
write_eeprom(0xf6,temp+0x30);
temp=x/100;
write_eeprom(0xf5,temp+0x30);
}
8.5. led matrix (595 va 154) ket noi rs232
#include <16f88.h>
#include
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=10000000)
#use rs232(baud=4800,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9)
#include
#include
// Dinh nghia cac chan cho ket noi 74595
#bit data = 0x06.1
#bit clk = 0x06.0
#bit latch = 0x06.3
// Bo nho dem man hinh hien thi
int8 buff_disp[17]; //Bo nho dem cho man hinh LED
int8 max_char=24; //SO ky tu hien thi toi da
int8 time; //Bien quy dinh toc do chu chay
//=========KHAI BAO CAC CHUONH TRINH CON================
int8 doc_eeprom(int8 addr);
void send_i2c(int8 temp);
void display();
void copy_2_ram1(int8 index_char);
void copy_2_ram2(int8 index_char);
void update_eeprom();
//=============================================
//===========Chuong trinh chinh================
void main() {
int8 i,j;
#bit update_flag = 0x06.4
char const a[25]= " Bang thong tin dien tu ";// Ky tu NULL duoc them vao cuoi
TRISA=0x10; // Thiet lap lam dau ra
trisb=0x04;
setup_adc_ports(sAN4);
setup_adc(ADC_CLOCK_INTERNAL);
//ra4=1;
//max_char=sizeof(a);
for(i=0;i<25;++i)
write_eeprom(i,a[i]);
write_eeprom(0xff,max_char);// Luu so ky tu toi da vao ROM
//max_char=doc_eeprom(0xff); //Doc lay gia tri
do {
for (i=0;i<=16;i++) // Clear RAM of buff_disp
buff_disp[i]=0xff;
if(update_flag)
update_eeprom();
for (i=0;i<=max_char;i++) // Begin of text
{
j=doc_eeprom(i)-32;
if (j<=51)
copy_2_ram1(j);
else
{
j=j-52;
copy_2_ram2(j);
}
}
} while(true);
//ra4=1;
}
//========= END MAIN ==============
// === CAC CHUONG TRINH CON =========
//=======Gui du lieu theo duong I2C============
void send_i2c(int8 temp) {
#bit flag_bit = temp.7
int8 i;
for(i=0;i<8;i++)
{
if(flag_bit)
data=1; //bit 1
else data=0; //bit 0
clk=1;
delay_us(1);
clk=0;
temp<<=1; // Dich trai 1 bit
}
latch=1;
latch=0;
}
//===========Chuong trinh con hien thi=========
void display() {
int8 disp_count,column_count;
int8 i;
delay_us(10);
time = read_adc();
time = (time/255)*5;
for (i=0;i<=time;i++) //Toc do chu chay thay doi boi bien time
{
column_count=0;
for(disp_count=16;disp_count>0;disp_count--)
{
send_i2c(buff_disp[disp_count]);
PORTA=column_count;
delay_ms(2);
//send_i2c(0xff);
column_count++;
}
}
}
//========Copy to Ram1=====================
void copy_2_ram1(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
{ buff_disp[i]= buff_disp[i-1]; } //Dich RAM sang trai
//Luu ma ascii vao RAM
buff_disp[0]=font[index_char].b[j];
// Goi hien thi
display();
}
buff_disp[0]=0xff;
}
//========Copy to Ram 2===================
void copy_2_ram2(int8 index_char) {
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
{ buff_disp[i]= buff_disp[i-1]; } //Dich RAM sang trai
//Luu ma ascii vao RAM
buff_disp[0]=font2[index_char].b[j];
// Goi hien thi
display();
}
buff_disp[0]=0xff; // Them mot khoang trang giua hai ky tu
}
//=========Update EEPROM===================
void update_eeprom() {
byte i,j,addr,max;
char string[64];
//char answer;
#locate i=0x33
#locate j=0x34
#locate addr=0x35
#locate max=0x36
#locate string = 0x37
//ra4=0;
printf("\r\n\n256 byte EEPROM of PIC16F88:\r\n (from 0x00 to 0xFF) \r\n"); // Display contents of the first 64
for(i=0; i<=15; ++i) // bytes of the data EEPROM in hex
{
for(j=0; j<=15; ++j)
printf( "%2x ", doc_eeprom( i*16+j ) );
printf("\n\r");
}
//ra4=1;
printf("\r\nTong so chu cua ban tin: %2x", doc_eeprom(0xff));
printf("\r\nSo chu hien thi moi la: ");
max_char=gethex();
write_eeprom(0xff,max_char);
printf("\r\nDia chi EPROM can thay doi(2 chu so hexa): ");
addr = gethex();
if (addr >= max_char)
write_eeprom(0xff,addr);
printf("\r\nSo ky tu toi da them vao: ");
max = gethex(); // Tra ve gia tri Hexa
if(max >= max_char)
write_eeprom(0xff,max); // Cap nhat so ky tu
printf("\r\nKy tu moi: ");
get_string(string,max+1);
for (i=0;i{
write_eeprom(addr,string[i]);
addr=addr+1;
}
// Ket thuc viec cap nhat, tro ve hien thi
}
//=============READ EEPROM=====================
int8 doc_eeprom(byte addr)
{
EEADR=addr;
RD=1;
return(EEDATA);
}
8.6. led matrix ver 1.2
#include <16f88.h>
#include
#fuses NOWDT,HS, NOPUT, NOPROTECT
#use delay(clock=10000000)
#use rs232(baud=4800,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9)
int8 buff_disp[17];
//char string[50];
// Khai bao cac ham Ngat
//#int_RDA
//RDA_isr()
//{
//}
typedef struct {
int8 b[5]; /* Data */
}T_font;
const T_font font[]={
//******************BANG MA ASCII****************
//ascii_code:
0xFF,0xFF,0xFF,0xFF,0xFF,//SPACE 0
0xFF,0xFF,0xA0,0xFF,0xFF,//! 1
0xFF,0xFF,0xF8,0xF4,0xFF,//' 2
0xEB,0x80,0xEB,0x80,0xEB,//# 3
0xDB,0xD5,0x80,0xD5,0xED,//$ 4
0xD8,0xEA,0x94,0xAB,0x8D,//% 5
0xC9,0xB6,0xA9,0xDF,0xAF,//& 6
0xFF,0xFF,0xF8,0xF4,0xFF,//' 7
0xFF,0xE3,0xDD,0xBE,0xFF,//( 8
0xFF,0xBE,0xDD,0xE3,0xFF,//) 9
0xD5,0xE3,0x80,0xE3,0xD5,//* 10
0xF7,0xF7,0xC1,0xF7,0xF7,//+ 11
0xFF,0xA7,0xC7,0xFF,0xFF,//, 12
0xF7,0xF7,0xF7,0xF7,0xF7,//- 13
0xFF,0x9F,0x9F,0xFF,0xFF,//x 14
0xFF,0xC9,0xC9,0xFF,0xFF,/// 15
0xC1,0xAE,0xB6,0xBA,0xC1,//0 16
0xFF,0xBD,0x80,0xBF,0xFF,//1 17
0x8D,0xB6,0xB6,0xB6,0xB9,//2 18
0xDD,0xBE,0xB6,0xB6,0xC9,//3 19
0xE7,0xEB,0xED,0x80,0xEF,//4 20
0xD8,0xBA,0xBA,0xBA,0xC6,//5 21
0xC3,0xB5,0xB6,0xB6,0xCF,//6 22
0xFE,0x8E,0xF6,0xFA,0xFC,//7 23
0xC9,0xB6,0xB6,0xB6,0xC9,//8 24
0xF9,0xB6,0xBE,0xD6,0xE1,//9 25
0xFF,0xC9,0xC9,0xFF,0xFF,//: 26
0xFF,0xA4,0xC4,0xFF,0xFF,//// 27
0xF7,0xEB,0xDD,0xBE,0xFF,//< 28
0xEB,0xEB,0xEB,0xEB,0xEB,//= 29
0xFF,0xBE,0xDD,0xEB,0xF7,//> 30
0xFD,0xFE,0xAE,0xF6,0xF9,//? 31
0xCD,0xB6,0x8E,0xBE,0xC1,//@ 32
0x83,0xF5,0xF6,0xF5,0x83,//A 33
0xBE,0x80,0xB6,0xB6,0xC9,//B 34
0xC1,0xBE,0xBE,0xBE,0xDD,//C 35
0xBE,0x80,0xBE,0xBE,0xC1,//D 36
0x80,0xB6,0xB6,0xB6,0xBE,//E 37
0x80,0xF6,0xF6,0xFE,0xFE,//F 38
0xC1,0xBE,0xB6,0xB6,0xC5,//G 39
0x80,0xF7,0xF7,0xF7,0x80,//H 40
0xFF,0xBE,0x80,0xBE,0xFF,//I 41
0xDF,0xBF,0xBE,0xC0,0xFE,//J 42
0x80,0xF7,0xEB,0xDD,0xBE,//K 43
0x80,0xBF,0xBF,0xBF,0xFF,//L 44
0x80,0xFD,0xF3,0xFD,0x80,//M 45
0x80,0xFD,0xFB,0xF7,0x80,//N 46
0xC1,0xBE,0xBE,0xBE,0xC1,//O 47
0x80,0xF6,0xF6,0xF6,0xF9,//P 48
0xC1,0xBE,0xAE,0xDE,0xA1,//Q 49
0x80,0xF6,0xE6,0xD6,0xB9,//R 50
0xD9,0xB6,0xB6,0xB6,0xCD,//S 51
};
//Phan tu hai
const T_font font2[]={
0xFE,0xFE,0x80,0xFE,0xFE,//T 52
0xC0,0xBF,0xBF,0xBF,0xC0,//U 53
0xE0,0xDF,0xBF,0xDF,0xE0,//V 54
0xC0,0xBF,0xCF,0xBF,0xC0,//W 55
0x9C,0xEB,0xF7,0xEB,0x9C,//X 56
0xFC,0xFB,0x87,0xFB,0xFC,//Y89 24 57
0x9E,0xAE,0xB6,0xBA,0xBC,//Z90 25 58
0xFF,0x80,0xBE,0xBE,0xFF,//[ 59
0xFD,0xFB,0xF7,0xEF,0xDF,//\ 60
0xFF,0xBE,0xBE,0x80,0xFF,//] 61
0xFB,0xE1,0xE0,0xE1,0xFB,//^ 62
0x7F,0x7F,0x7F,0x7F,0x7F,//_ 63
0xFF,0xFF,0xF8,0xF4,0xFF,//' 64
0xDF,0xAB,0xAB,0xAB,0xC7,//a 65
0x80,0xC7,0xBB,0xBB,0xC7,//b
0xFF,0xC7,0xBB,0xBB,0xBB,//c
0xC7,0xBB,0xBB,0xC7,0x80,//d
0xC7,0xAB,0xAB,0xAB,0xF7,//e 69
0xF7,0x81,0xF6,0xF6,0xFD,//f
0xF7,0xAB,0xAB,0xAB,0xC3,//g 71
0x80,0xF7,0xFB,0xFB,0x87,//h 72
0xFF,0xBB,0x82,0xBF,0xFF,//i 73
0xDF,0xBF,0xBB,0xC2,0xFF,//j 74
0xFF,0x80,0xEF,0xD7,0xBB,//k 75
0xFF,0xBE,0x80,0xBF,0xFF,//l 76
0x83,0xFB,0x87,0xFB,0x87,//m 77
0x83,0xF7,0xFB,0xFB,0x87,//n 78
0xC7,0xBB,0xBB,0xBB,0xC7,//o 79
0x83,0xEB,0xEB,0xEB,0xF7,//p 80
0xF7,0xEB,0xEB,0xEB,0x83,//q 81
0x83,0xF7,0xFB,0xFB,0xF7,//r 82
0xB7,0xAB,0xAB,0xAB,0xDB,//s 83
0xFF,0xFB,0xC0,0xBB,0xBB,//t 84
0xC3,0xBF,0xBF,0xDF,0x83,//u 85
0xE3,0xDF,0xBF,0xDF,0xE3,//v 86
0xC3,0xBF,0xCF,0xBF,0xC3,//w 87
0xBB,0xD7,0xEF,0xD7,0xBB,//x 88
0xF3,0xAF,0xAF,0xAF,0xC3,//y 89
0xBB,0x9B,0xAB,0xB3,0xBB,//z 90
0xFB,0xE1,0xE0,0xE1,0xFB,//^ 92
0xE3,0xE3,0xC1,0xE3,0xF7,//->93
0xF7,0xE3,0xC1,0xE3,0xE3,//<-94
0xEF,0xC3,0x83,0xC3,0xEF,//95
0xFF,0xFF,0xFF,0xFF,0xFF//BLANK CHAR 96
};
// End of code table
//=========CAC CHUONH TRINH CON================
byte doc_eeprom(byte addr);
void viet_eeprom(byte addr,byte data);
//===========Chuong trinh con hien thi=========
void display()
{
int8 disp_count,column_count;
int8 time;
for (time=0;time<6;time++)
{
column_count=0;
for(disp_count=16;disp_count>0;disp_count--)
{
PORTB=buff_disp[disp_count];
PORTA=column_count;
delay_ms(2);
column_count++;
}
}
}
//========Copy to Ram1=====================
void copy_2_ram1(int8 index_char)
{
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
{ buff_disp[i]= buff_disp[i-1]; } //Dich RAM sang trai
//Luu ma ascii vao RAM
buff_disp[0]=font[index_char].b[j];
// Goi hien thi
display();
}
buff_disp[0]=0xff;
}
//========Copy to Ram 2===================
void copy_2_ram2(int8 index_char)
{
int8 i,j;
for (j=0;j<=5;j++)
{ // Dich RAM
for (i=16;i>0;i--)
{ buff_disp[i]= buff_disp[i-1]; } //Dich RAM sang trai
//Luu ma ascii vao RAM
buff_disp[0]=font2[index_char].b[j];
// Goi hien thi
display();
}
buff_disp[0]=0xff;
}
//===========Chuong trinh chinh================
void main()
{
int8 count,i;
int8 const max_char=56;
// Khai bao chuoi ky tu hien thi tai day
char const a[57]= {"Truong Dai Hoc Bach Khoa Ha noi. Khoa Dien tu-Vien Thong"};// Ky tu NULL duco them
// Khoi tao chuong trinh chinh
// Khoi tao ngat
//enable_interrupts(INT_RDA);
//enable_interrupts(GLOBAL);
//=================
// Ghi du lieu vao EEPROM
for(i=0;i<57;i++)
viet_eeprom(i,a[i]);
printf("Ban tin hien thi: \n\r");
for(i=0;i<57;i++)
printf("%c",a[i]); //dinh dang %c de bieu thi gui ky tu, \n\r la xuong dong
//neu dinh dang la %u thi la so nguyen ko dau
while(1)
{
// Clear RAM of buff_disp
for (i=0;i<=16;i++)
buff_disp[i]=0xff;
TRISA=0x00; // Thiet lap lam dau ra
TRISB=0x00;
// Begin of text
for (i=0;i<=max_char;i++)
{
count=a[i]-32;
if (count<=51)
copy_2_ram1(count);
else
{
count=count-52;
copy_2_ram2(count);
}
}
}
}
//=====Viet vao EEPROM=======================
void viet_eeprom(byte addr,byte data)
{
GIE=0; // disable all interrups
//EEIE=1;
eeadrh=0;
eedath=0;
EEADR=addr; // dia chi
EEDATA=data;// du lieu
EEPGD=0;
WREN=1; // cho phep viet vao EEPROM
EECON2=0x55;
EECON2=0xAA;
WR=1; // bat dau viet vao EEPROM
while(EEIF==0);// doi viet vao EEPROM ket thuc
GIE=1;
wren=0;
EEIF=0; // Bit EEIF phai ve 0 de viet nhung lan tiep theo
}
//===========Doc du lieu tu EEPROM=============
byte doc_eeprom(byte addr)
{
EEADR=addr;
RD=1;
return(EEDATA);
}
Chia sẻ với bạn bè của bạn: |