Tải bản đầy đủ - 0 (trang)
A. LƯU ĐỒ GIẢI THUẬT

A. LƯU ĐỒ GIẢI THUẬT

Tải bản đầy đủ - 0trang

S



Đ

S



Đ



B. CODE CHƯƠNG TRÌNH



#include <18F4520.h>

#include

91



#include

#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,

NOLVP, NOCPD, NOWRT

#use delay (clock=20000000)

#include

// Dinh nghia cac chan cho ket noi 74595\\

#define clk pin_a0

#define data pin_a1

#define latch pin_a2

#define PHONE_NUM "01693580713"

unsigned char str[60],str1[100],str2[30],str3[12];

char ch; int kt,is,isti,ngat,idex,idex1,index,index1;

// Bo nho dem man hinh hien thi

int8 ha[8] = {1,2,4,8,16,32,64,128};

int8 buff_disp[65];



//Bo nho dem cho man hinh LED



int8 buff_disp1[65];

int8 max_char=28;

int8 time=5;



//So ky tu hien thi toi da

//Bien quy dinh toc do chu chay



int8 count=0; int isrun=0;

char dt[250]="Welcome SMS Led Matrix 16x64";

//=========KHAI BAO CAC CHUONH TRINH CON================

void send_2_595(int8 temp);

void send_2_5951(int8 temp);

void display();

void copy_2_ram1(int8 bg,int end);

void copy_2_ram2(int8 bg,int end);

92



void copy_2_ram3(int8 bg,int end);

void copy_2_ram4(int8 bg,int end);

void copy_2_ram5(int8 bg,int end);

void luudata();

void send_sms();

int kiemtra();

int kiemtra1();

void goidien();

void luusms();

//=============================================

#INT_RDA

Receive_isr()

{

ch = getc();

if(isti==1) //cho phep nhan khi da khoi tao thanh cong

{

if(ch==10 && index ==0) is=1; //bat dau cho phep nhan chuoi

if(ch==10 && index>0) {idex=index; ngat=1; isti = 2; } //KHI KET THUC

MOT CHUOI

if(ch!=10 && ch!=13 && is == 1) { str[index] = ch; index++; }

}

if(isti==2) //cho phep nhan khi da khoi tao thanh cong

{

if(ch==10 && index1 ==0) is=1; //bat dau cho phep nhan chuoi

if(ch==10 && index1>0) {idex1=index1; ngat=2; isti = 0;}// max_char = index11;luudata();} //KHI KET THUC MOT CHUOI

93



if(ch!=10 && ch!=13 && is == 1) { str1[index1] = ch; if(index1<100) index1+

+; }

}

}

//==============================

void luudata()

{

int t;

for(t=0;t
write_eeprom(0xff,max_char);



// Luu so ky tu toi da vao ROM



isrun=1;

}



//===========Chuong trinh chinh================

void main() {

int8 i,j;

//===========================================

set_tris_a(0x00);

set_tris_b(0x00);

set_tris_c(0xff);

set_tris_d(0x00);

delay_ms(10);

enable_interrupts(INT_RDA);

ENABLE_INTERRUPTS(GLOBAL);

delay_ms(10000);



94



while(true)

{

index = 0; is = 0; isti = 0;

puts("AT"); putc(13); isti = 1; delay_ms(500);

strcpy(str2,"OK");

if(kiemtra()==1)

{

isti = 0;

puts("AT+IPR=9600"); putc(13); delay_ms(800);

puts("ATE1"); putc(13); delay_ms(100);

puts("AT+CMGF=1"); putc(13); delay_ms(800);

puts("AT+CMGD=1"); putc(13); delay_ms(800);

break;

}

}

//===========================================

//luudata();

strcpy(str3,"KT xong"); send_sms(); delay_ms(5000);

puts("01693580713;"); putc(13); delay_ms(10000); puts("ATH"); putc(13);



idex = 0; index = 0; ngat= 0; is = 0; isti = 1;



tudau:

max_char = read_eeprom(0xff);

//time = read_eeprom(200); if(time>20)

//=======BEGIN DISPLAY FUNCTION==============

95



//Doan chuong trinh nay se hien thi noi dung ban tin luu trong EEPROM

isrun=0;

if(max_char>200) { max_char = 28; for(i=0;i
for(i=0;i


while(true)

{

if(ngat!=0) //co tin hieu dieu khien

{

isti = 0;

strcpy(str2,"CMTI");

if(kiemtra()==1)

{



kt = 1;

while(kt<2)

{

idex = 0; idex1 = 0; index = 0; index1 = 0; ngat = 0; isti = 0; is = 0;

puts("at+cmgr=1"); putc(13); isti = 1;

while(ngat != 2) {} isti = 0;

//-----------puts("AT+CMGD=1"); putc(13); delay_ms(500);

puts("AT+CMGD=1"); putc(13); delay_ms(500);

strcpy(str2,"*");

if(kiemtra1()==1)

{

luusms();

strcpy(str3,"Da nhan "); send_sms(); delay_ms(300);

96



kt = 2;

}

//-----------------kt++; if(kt==2) { strcpy(str3,"SAI CUPHAP"); send_sms();

delay_ms(300); }

puts("at+cmgd=1"); putc(13); delay_ms(2000);

} //end kt < 2

} //end kt CMTI

idex = 0; idex1 = 0; index1 = 0; index = 0; ngat = 0; isti = 1; is = 0;

} //end co tin hieu dk

for (i=0;i<=64;i++)



// Clear RAM of buff_disp



{ buff_disp[i]= 0x00; //font2h[60+i];

buff_disp1[i]= 0x00;} //font2l[60+i]; }

for(i=0;i
{ j = dt[i];

if(j<23) //5 mang cua bo font: 1->22; 23->42; 43->61; 62->84; 85->

copy_2_ram1(font1[j-1],font1[j]);

else

{

if(j<43) { j=j-22; copy_2_ram2(font2[j-1],font2[j]); }

else

{

if(j<62) { j=j-42; copy_2_ram3(font3[j-1],font3[j]); }

else

{

if(j<85) { j=j-61; copy_2_ram4(font4[j-1],font4[j]); }

97



else { j=j-84; copy_2_ram5(font5[j-1],font5[j]); }

}

}

}

if(isrun==1) goto tudau;

}

for (j=0;j<64;j++)

{

for (i=64;i>0;i--)

{

{ buff_disp[i]= buff_disp[i-1]; buff_disp1[i]= buff_disp1[i-1];}

RAM sang trai

buff_disp[0]=0x00; buff_disp1[0]=0x00; // Luu ma ascii vao RAM

} display(); // Goi hien thi

if(isrun==1) goto tudau;

}

}

}

//========= END MAIN ==============



// === CAC CHUONG TRINH CON =========

//=======Gui du lieu theo duong noi tiep toi 595============

void send_2_595(int8 temp)

{

output_low(clk);

for(count=0;count<64;count++)

98



// Dich



{

if((buff_disp[count] & temp)>0)

output_high(data);



//bit 1



else output_low(data); //bit 0

output_high(clk);

output_low(clk);

}

}

void send_2_5951(int8 temp)

{

output_low(clk);

for(count=0;count<64;count++)

{

if((buff_disp1[count] & temp)>0)

output_high(data);



//bit 1



else output_low(data); //bit 0

output_high(clk);

output_low(clk);

}

}

//===========Chuong trinh con hien thi=========

void display() {

int8 i,j;



for (i=0;i


//Toc do chu chay thay doi boi bien time



{

99



for(j=8;j>0;j--)

{

send_2_595(ha[j-1]);

output_B(0x00);output_d(0x00);

output_high(latch);



//Chot du lieu



output_low(latch);

output_B(ha[j-1]); //255-buff_disp[count];

delay_us(8);

}

for(j=8;j>0;j--)

{

send_2_5951(ha[j-1]);

output_d(0x00); output_b(0x00);

output_high(latch);



//Chot du lieu



output_low(latch);

output_D(ha[j-1]); //255-buff_disp[count];

delay_us(8);

}

}

}

//========Copy to Ram1=====================

void copy_2_ram1(int8 bg,int end)

{

int8 i,j;

100



for (j=bg;j
{



// Dich RAM



for (i=64;i>0;i--)

{ buff_disp[i]= buff_disp[i-1]; buff_disp1[i]= buff_disp1[i-1];}

sang trai



// Dich RAM



buff_disp[0]=font1h[j]; buff_disp1[0]=font1l[j]; // Luu ma ascii vao RAM

display(); // Goi hien thi

}

buff_disp[0]=0x00; buff_disp1[0]=0x00;

}

//========Copy to Ram2=====================

void copy_2_ram2(int8 bg,int end)

{

int8 i,j;



for (j=bg;j
{



// Dich RAM



for (i=64;i>0;i--)

{ buff_disp[i]= buff_disp[i-1]; buff_disp1[i]= buff_disp1[i-1];}

sang trai



// Dich RAM



buff_disp[0]=font2h[j]; buff_disp1[0]=font2l[j]; // Luu ma ascii vao RAM

display(); // Goi hien thi

}

buff_disp[0]=0x00; buff_disp1[0]=0x00;

}

//========Copy to Ram3=====================

101



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

A. LƯU ĐỒ GIẢI THUẬT

Tải bản đầy đủ ngay(0 tr)

×