Đồ án Thiết kế công cụ phân tích khuôn dạng số trong điều khiển từ xa của ti vi

Chân nhận dạng được cấu hình kích khởi cạnh âm , căn cứ vào cách mã hóa bit 0,1. Để có thể xác định đâu là bit 0 và 1 ta cần phãi xác định khoảng thời gian giũa hai lần xảy ra ngắt ngoài. Để làm được điều này ta cần cấu hình một timer của vi điều khiển xảy ra tràn sau một khoảng thời gian nào đó (khoảng thời gian nàylà tối ưu khi dùng để xác định các bit 0 và 1). Căn cứ vào các tham số quy định cho chuẩn REC chọn thời gian tràn của bộ định thời là 1ms . Thời gian giữa 2 lần ngắt với bít 0 là khoảng 5ms. bit 0: số lần tràn bộ định thời 2 là trong khoảng (4->6). Thời gian giữa 2 lần ngắt với bít 1 là khoảng 7.5ms. bit 1: số lần tràn là trong khoảng (6->9). Trình phục ngắt do timer 2 sẽ tăng lên một để đếm số lần tràn sau mỗi lần tràn.

doc139 trang | Chia sẻ: oanh_nt | Lượt xem: 1211 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Đồ án Thiết kế công cụ phân tích khuôn dạng số trong điều khiển từ xa của ti vi, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
oid main(void) { //khai bao cac bien... UINT8 x,y; /*cac bien 8 bit dung de truyen tu ma cac chuan ve PC*/ // ----khoi tao cac bien...--------- Data_Ready=0;//khoi tao Data_Ready//DEBUG... P3_2=1; //chan input doc vao//DEBUG P1_0=0; P1_1=1; /*******************************************/ EA=1; /*cho phep tat ca cac ngat*///DEBUG... /*************init_port_serial***********************/ Send_Active = 0; //chua vao trang thai truyen Send_Full=0; //truyen duoc ngay dem luu ttruoc khi phat rong ... Out_Buffer_Pos_Start = 0; //khoi tao mang phat rong..... Out_Buffer_Pos_End = 0; //khoi tao mang phat rong..... //khoi tao cac tham so cho cong noi tiep SCON = 0x50;//UART 8 bit TMOD = 0x21; // timer1 mode 2 8 bit auto reload ,timer0 che do 16 bit PCON |= 0x80;//SMOD=1 nhan doi toc do baud.... TH1 = 0xFA;//9600 baud TR1 = 1;//timer1 hoat dong //chua cho phep ngat do port serial... vi chua co du lieu truyen //--------------init_timer0----------------- ET0=1;// cho phep ngat do timer 0 TF0=0;//xoa co tran... TR0=0;//dam bao la timer dang dung ... /*************Init_Ex0***********************/ IT0=1; /*chon loai ngat tac dong canh....*/ PX0=1; //uu tien ngat do EX0 EX0=1; /*cho phep ngat ngoai */ /*------------************-----------------*/ //--------mac dinh la giai ma cho chuan RC5........ //---------truyen ve chuoi dinh dang chop chuan RC5----// while(1) { if (Data_Ready) // kiem tra co du lieu tien hanh doc { y=RC5_Container&0xff; /*byte thap chuan RC5*/ x=(RC5_Container>>8)&0x3f; /*byte cao chuan RC5*/ Transmit_Data(y,x);/*truyen byte thap, truyen byte cao*/ Data_Ready=0; } //end if }//end while }//end mains //--------------------------------------------------\ Chöông trình vieát giaûi maõ cho chuaån REC…. #include //---------------****************------------------// #define UINT8 unsigned char #define UINT16 unsigned int #define UINT32 unsigned long //------------khai bao do dai mang....----------// #define OUT_BUFFER_LEN 8 // size of serial transmission buffer //--------------********************-------------------// //cac bien globlal var.... UINT8 Out_Pos_Start; // transmission buffer start index UINT8 Out_Pos_End; // transmission buffer end index UINT8 idata Out_Buffer[OUT_BUFFER_LEN]; // storage for transmission buffer bit Send_Full; // flag: marks transmit buffer full bit Send_Active; // flag: marks transmitter active UINT8 Bit_Counter; //bien dung de dem so bit*/ UINT8 Timer0_Tick; UINT16 Container; //bien toan cuc de chua tu ma cua cac chuan*/ bit Data_Ready; //bien bao hieu da co du lieu UINT16 Container; //---------------********************------------------// //khai bao cac prototype function... void put_buffer (UINT8 c); //dat byte can truyen vao bo dem hoac SBUF void putbyte (UINT8 c);//truyen di mot byte nao do void Transmit_data(UINT8 x,UINT8 y ); //*******************************************************// void Serial_Port_Isr (void) interrupt 4 { if (TI != 0) // dem phat rong { TI = 0; // xoa co ngat if (Out_Pos_Start != Out_Pos_End) { // chua tryen het mang SBUF = Out_Buffer[Out_Pos_Start++ & (OUT_BUFFER_LEN-1)]; // truyen so leu trong mang Send_Full = 0; // khi truyen xoa co bao tran bo dem } else { // truyen het Send_Active = 0; // xoa trang thai dang truyen } } } //------------------------------------------------------ /* put_buffer: ghi mot byte ra SBUF hoac bo dem phat */ /*da test va hoat dong chinh xac....*/ void put_buffer (UINT8 c) //dat byte ca truyen vao thanh ghi SBUF hoac bo dem truyen { //chi dat vao bo dem neu dem chua day if (!Send_Full) //dem chua day { // chi truyen nau bo dem khac rong if (!Send_Active) //dang khong truyen { // if transmitter not active: Send_Active = 1; // truyen byte dau tien SBUF = c; // dua ra SBUF de bat dau truyen } else // dang truyen { ES = 0; // cam ngat neu dang truyen mot byte nao do trong bo dem ... Out_Buffer[Out_Pos_End++ & (OUT_BUFFER_LEN-1)] = c; // dat byte do vao trong bo dem if (((Out_Pos_End ^ Out_Pos_Start) & (OUT_BUFFER_LEN-1)) == 0) //dem day { Send_Full = 1; //bao dem day } // dem day .... ES = 1; // cho phep ngat de truyen tiep } } } //------------------------------------------------------- void putbyte (UINT8 c) { /*da test va hoat dong chinh xac....*/ while (Send_Full); // doi den khi co khoang trong trong bo dem put_buffer (c); // dat byte can truyen vao trong bo dem ... } //------------------------------------------------------- void Transmit_data(UINT8 x,UINT8 y ) { ES=1;// cho phep ngat do portserial TI=1;//truyen byte dau tien... putbyte(x);// cho x vao bo dem hoac truyen x putbyte(y);//cho y vao bo dem hoac truyen y while(Send_Active!=0)// doi den khi truyen xong { } ES=0;//cam ngat do port serial... } //-------------------------------------------------------------------------- void Timer0_Isr_Decode_Standard(void) interrupt 1 /*ham nay se tu dong chay sau moi lan bo dinh thoi tran*/ {///tu nap 8 bit khong can nap lai vao... TR0=0; TH0 =0xFE;//-500us tinh cho thach anh 11.0592MHZ TL0 =0x34;// -500 us khong con gi khi ma nuang khogn con gi ma kho TR0=1; if(Timer0_Tick<100)//i can toi da la 100 tick la du Timer0_Tick++;///tang so timer0_tick } //--------------------------------------------------------------------------- void Decoder_Standard(void) interrupt 0 //nhan dang tren chan gnat INT0 { /*chan ngat INT0*/ UINT8 Last_Count_Tick;/*dung de chua thoi gian do duoc cua mot bit*/ //trinh phuc vu ngat INT0 xay ra sau khi co ngat P1_0=!P1_0;//nhap nhay khi co tia hong ngoai if(Data_Ready==0)//chuyen giao xong bien toan cuc va khong co su thay doi Mode { Last_Count_Tick=Timer0_Tick;//doc bien count Timer0_Tick=0;// reset lai Timer0_Tick Container=Container<<1;//dich trai mot bit if(Last_Count_Tick>=12&&Last_Count_Tick<=18)//7.5 ms Container|=1;// 25,35 chua tinh chinh xac else if((Last_Count_Tick>18)||(Last_Count_Tick<6))//5 ms// loi 1 bit { P1_1=!P1_1;///daochan P1_3 Bit_Counter=12;// khoi tao lai bo dem Container=0;// bien chua bang 0 Data_Ready=0; // khong cam ngat ngoai } Bit_Counter--;//giam bo dem di if(Bit_Counter==0)//nhan du so lieu { Data_Ready=1;//giai ma xong P1_2=!P1_2; // khong cam ngat ngoai } }//end if ... } //end ham void main(void) { //khai bao cac bien... // ----khoi tao cac bien...--------- Data_Ready=0;//khoi tao Data_Ready//DEBUG... Bit_Counter=12; Container=0;// bien chua bang P3_2=1; //chan input doc vao//DEBUG P3_3=1; //chan input doc vao//DEBUG P1_0=0; P1_1=1; /*******************************************/ EA=1; /*cho phep tat ca cac ngat*///DEBUG... /*************init_port_serial***********************/ //khoi tao cac tham so cho cong noi tiep SCON = 0x50;//UART 8 bit TMOD = 0x21; // timer1,0 mode 2 8 bit,timer0 16 bit... PCON |= 0x80;//SMOD=1 nhan doi toc do baud.... TH1 = 0xFA;//9600 baud TR1 = 1;//timer1 hoat dong TI=1; //chua cho phep ngat do port serial... vi chua co du lieu truyen //--------------init_timer0----------------- TR0=0; TF0=0;//xoa co tran... ET0=1;// cho phep ngat do timer 0 TH0=0xFE;//-200us tinh cho thach anh 11.0592MHZ TL0=0x34;// -200 us khong con gi khi ma nuang khogn con gi ma khong TR0=1;//dam bao la timer dang dung ... /*************Init_Ex0***********************/ IT0=1; /*chon loai ngat tac dong canh....*/ EX0=1; /*cho phep ngat ngoai */ /*------------************-----------------*/ //--------mac dinh la giai ma cho chuan RC5........ //---------truyen ve chuoi dinh dang chop chuan RC5----// Transmit_data(255,65);//truyen 255,64 while(1) { if (Data_Ready) // kiem tra co du lieu tien hanh doc { Transmit_data(Container&0xff,(Container>>8)&0x3f); /*byte thap chuan REC*/ /*byte cao chuan REC*/ Container=0;// bien chua bang Bit_Counter=12;// khoi tao lai bo dem Data_Ready=0; } //end if }//end while }//end mains 2. Maõ nguoàn chöông trình thu treân PC. ***************************************** /*------------------*******BKHN*********------------------------------*/ /*------------------*******DTVT*********------------------------------*/ /*------------------*******DT_CD1A_K44*********------------------------*/ /*------------------*******NGUYEN_QUOC_HUNG*********-------------------*/ #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define MAX 50 #define ESC 27 #define NONE_EV 0 #define DATA_EV 1 #define OVER_EV 2 #define ESC_EV 3 #define Format0 255 #define Format1 255 #define Format2 255 #define Format3 64 #define PORT1 0x3F8//cong COM1 #define PORT2 0x2F8//cong COM2 enum bool {true=1,false=0} ; int Event; int Size_Of_Receiver_Buffer; int Current_Size_Of_Receiver_Buffer;// unsigned char Receiver_Buffer[MAX]; unsigned char Format[4];////mac dinh la chuan RC5....... int Com_Port_Address; char * Input_File_Name(void) { bool ok; char * File_Name; do { puts("INPUT FILE NAME.."); puts("LENGTH OF FILE<=25 ... "); gets(File_Name); puts("HIT ANY KEY TO CONTINUE..."); getch(); if( ( (strlen(File_Name)==0) || (strlen(File_Name)>25) ) ) ok=false; else ok=true; if (ok==false) { puts (" FileName ERROR... "); puts("RE_INPUT FILE NAME..."); puts("HIT ONE KEY..."); getch(); } } while( ok==false); return File_Name; } //------------------------------------------------- int Choice_Com_Port (void ) //tra ve ve dia chi cong COM { bool ok; int Choice_Com; int Com_Port; puts("CHOICE COMPORT...."); puts("COM1 address_port 0x3F8...."); puts("COM2 address_port 0x2F8...."); puts("INPUT AN NUMBER INTERGER....."); puts("1 AS COM1...."); puts("OTHER AS COM2...."); puts("KEY INTERGER NUMBER..."); puts("OK........"); puts("HIT ANY KEY..."); getch(); puts("INPUT AN NUMBER INTERGER...."); scanf("%d",&Choice_Com); switch(Choice_Com) { case 2:Com_Port=PORT2; puts("COM2 HAVE BEEN CHOICED"); puts("HIT ANY KEY..."); getch(); break; default:Com_Port=PORT1; puts("COM1 HAVE BEEN CHOICED"); puts("HIT ANY KEY..."); getch(); break; } return Com_Port ; }//end function //------------------------------------------------------------ FILE * open_file(char *File_Name) { FILE *fp; //con tro file fp=fopen(File_Name ,"wb" ); //mo tep doc kieu nhi phan return fp; } //-------------------------------------------------- FILE * Re_Open_File(char *File_Name) { FILE *fp; //con tro file fp=fopen(File_Name ,"ab" ); //mo tep ghi bo xung return fp; } void Com_Port_setting(int Com_Port_Add , int choicebaurate) { outportb(Com_Port_Add + 3 , 0x80); /* SET DLAB ON */ switch(choicebaurate) { case 1: outportb( Com_Port_Add+ 0 , 0x30);//2400baud puts(" YOU HAVE CHOICED 2400 BAUD"); puts("HIT ANY KEY..."); getch(); break; case 2: outportb(Com_Port_Add + 0 , 0x18);//4800 puts(" YOU HAVE CHOICED 4800 BAUD"); puts("HIT ANY KEY..."); getch(); break; case 3: outportb( Com_Port_Add+ 0 , 0x06);//19200 puts(" YOU HAVE CHOICED 19200 BAUD"); puts("HIT ANY KEY..."); getch(); break; case 4: outportb( Com_Port_Add+ 0 , 0x02);//56700 puts(" YOU HAVE CHOICED 56700 BAUD"); puts("HIT ANY KEY..."); getch(); break; case 5: outportb( Com_Port_Add+ 0 , 0x01);//115200 puts(" YOU HAVE CHOICED 115200 BAUD"); puts("HIT ANY KEY..."); getch(); break; default:outportb( Com_Port_Add+ 0 , 0x0C);//9600 puts(" YOU HAVE CHOICED 9600 BAUD"); puts("HIT ANY KEY..."); getch(); break; } outportb(Com_Port_Add + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */ outportb(Com_Port_Add + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */ outportb(Com_Port_Add + 2 , 0xC3); /* FIFO Control Register */ outportb(Com_Port_Add + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */ } void Wait_For_Events(int *Event) { int ch,status; if(Size_Of_Receiver_Buffer==MAX) { *Event=OVER_EV;//dem tran return; } status=inportb(Com_Port_Address+5)&0x01; //LSR if(status==0x01) { *Event=DATA_EV;//co du lieu return; } if(kbhit()) { ch=getch(); if(ch==ESC) { *Event=ESC_EV;//thoat return; } } *Event=NONE_EV; } void Init_Parametter_Of_Comport() { int Choice_Baud_Rate; Com_Port_Address= Choice_Com_Port(); puts("IF YOU HIT ESCAPPE ,THE PROGRAM WILL AUTOMATICALLY WRITE BUFFER IN FILE BEFOR EXIT..."); puts("WHEN BUFFER FLOW ,AUTOMATICALLY WRITEFILE ..."); puts("HIT ESC TO EXIT..."); puts("HIT A RC5_MODE DECODE..."); puts("HIT B REC MODE DECODE..."); puts("HIT C NEC MODE DECODE..."); puts("HIT ANY KEY TO CONTINUE ..."); getch(); clrscr(); Size_Of_Receiver_Buffer=2;//khoi gan bo dem Event=NONE_EV;//chua co du lieu puts(" CHOICE BAUD RATE..."); puts(" input an interger..."); puts("1 AS 2400 baud...."); puts("2 AS 4800 baud...."); puts("3 AS 19200 baud..."); puts("4 AS 56700baud...."); puts("5 AS 115200baud...."); puts("OTHER NUMBER AS 9600baud..."); puts("HIT ANY INTERGER NUMBER..."); scanf("%d",&Choice_Baud_Rate); printf("%d",Choice_Baud_Rate); Com_Port_setting( Com_Port_Address,Choice_Baud_Rate);//seupserial puts("CONTINUE"); puts("WAIT DATA TO RECEIVE..."); puts("AFTER WRITE TO FILE..."); puts("OK...."); Format[0]=Format0; //dua for mat vao Format[1]=Format1; Format[2]=Format2; //dua for mat vao Format[3]=Format3; } void main() { char* File_Name; FILE *fileptr; do { File_Name=Input_File_Name(); fileptr=open_file(File_Name); } while(fileptr==NULL); Init_Parametter_Of_Comport(); fwrite(Format,1,2,fileptr); // ghi Format vao truoc fclose(fileptr) ; fileptr=Re_Open_File(File_Name); if(fileptr==NULL) { puts("COUND NOT OPEN THIS FILE... "); puts("EXIT..."); exit(0); } while(TRUE) { Wait_For_Events(&Event); switch(Event) { case OVER_EV://tran ghi so lieu vao mang printf("\nBUFFER OVER FLOW..."); puts("WRITE FILE..."); fwrite(Receiver_Buffer,1,MAX,fileptr);//ghi file fclose(fileptr); puts ("IF YOU WANT REWRITE..."); puts("HIT ANY KEY IF YOU WANT..."); puts("CONTINUE..."); if (kbhit()) { puts("RE OPEN THIS FILE..."); fileptr=Re_Open_File(File_Name);//mo lai file ghi bo xung if (fileptr==NULL) { puts("COULD NOT REOPEN THIS FILE... "); exit(0); } puts("RESET Size_Of_Receiver_BufferOF Receiver_Buffer..."); Size_Of_Receiver_Buffer=0;//khoi tao lai bien Size_Of_Receiver_Buffer } break; case DATA_EV://co du lieu Receiver_Buffer[Size_Of_Receiver_Buffer]=inportb(Com_Port_Address); printf("%d",Receiver_Buffer[Size_Of_Receiver_Buffer]); Size_Of_Receiver_Buffer++; printf("\n BEING RECEIVED..."); break; case ESC_EV://nhan ESC thoat Current_Size_Of_Receiver_Buffer=Size_Of_Receiver_Buffer; fwrite(Receiver_Buffer,1,Current_Size_Of_Receiver_Buffer,fileptr);//ghi file fclose(fileptr); printf("\n HIT ANY KEY TO EXIT!..."); getch(); exit(0); break; } } } //----------------------------------------------------------------------------------------------- 3.chöông trình giaûi maõ hieån thò treân PC ************************************************************ /*------------------*******BKHN*********---------------------------------------------*/ /*------------------*******DTVT*********---------------------------------------------*/ /*------------------*******DT_CD1A_K44*********--------------------------------*/ /*------------------*******NGUYEN_QUOC_HUNG*********-------------------*/ #include #include #include #include #include #include #include #include #include #define UINT8 unsigned char #define UINT16 unsigned int #define UINT32 unsigned long #define LEFT 75 /* ma ASC mui ten sang trai*/ #define RIGH 77 #define ESC 27 /* ma ASC phim escape*/ #define RC5_DECDISP 64 /*mode giai ma cho chuan RC5*/ #define RECS80_DECDISP 65 /*mode giai ma cho chuan RECS80*/ #define NEC_DECDISP 66 /*mode giai ma cho chuan NEC*/ #define NORMAL_DECDISP 255 /*tri so byte can kiem tra truoc khi kiem tra mode */ #define FORMAT0 255 //cac ki tu dinh dang #define FORMAT1 255 //cac ki tu dinh dang typedef struct DISPLAY { UINT8 data; UINT8 mode; UINT8 pos; } ; typedef struct DS { /*khai bao danh sach moc noi kep ung voi chuan RC5va RECS80*/ struct DS * next; struct DS * prev; struct DISPLAY node; } LIST ; //----------------------------------------------------------// char Char_File_Name[30]; FILE *File_Ptr;// con tro file //-----------------------------------------------------------// enum bool {true = 1,false= 0}; UINT32 F_Con_Vert1 (UINT8 bytehigh,UINT8 bytelow);//bien doi 2 byte thanh tu ma UINT32 F_Con_Vert2(UINT8 x,UINT8 y,UINT8 z,UINT8 t);// bien doi 4 yte thanh tu m void F_Init_List(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr);//** void Insert_List( LIST** Header_List_Ptr,LIST**last,DISPLAY Node_Dis); //** void F_Make_List_Display(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr);// tao danh sach tu tep /** void F_Processcing_List(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr);// su li danh sach /* void Display_Decode(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr);// ham nay hien thi void RC5_Draw_Bit1(int bitnum); void RC5_Draw_Bit0(int bitnum); void RC5_Draw_Dataword(UINT32 RC5_DataWord ); void REC_Draw_Dataword(UINT32 REC_DataWord ); void NEC_Draw_Dataword(UINT32 NEC_DataWord); void REC_Draw_Bit(int x0,int y0,int Fill_pattern, int Fill_Color); void NEC_Draw_Bit(int x0,int y0,int width,int Fill_pattern, int Fill_Color); void Input_Char_File_Name(void); void Open_File(void ); LIST* Get_Header_List(LIST* list); LIST* Get_Tailer_List(LIST* list); void Init_Graphics(void ); void Free_List(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr);//** void Print_Data_In_File(void); // in noi dung file void Print_List(LIST*Header_List_Ptr); //in danh sach moc noi ra man hinh void main(void) {//---------------------Phan nhap ten tep---------------------- char ch; bool ok; LIST*Header_List_Ptr; LIST *Tailer_List_Ptr; puts("HIT ANY KEY TO START PROGRAM..."); getch(); do { puts("PRINT DATA IN FILE..."); puts("HIT ANY KEY..."); getch(); Print_Data_In_File(); //in cac phan tu cua tep ,sau 2 byte dau tien tro di puts("FOMAT OF FILE RIGH? ..."); puts("HIT ENTER IF RIGH ... "); puts("HIT OTHER KEY IF WRONG... "); ch=getch();//nhap vao xac nhan if(ch==13) ok=true; else { ok=false; puts("LOOP..."); getch(); } if( ok==true) break; } while(ok==false); puts("HIT KEY...TO CONTINUE..."); puts("INPUT THIS FILE TO DECODE... "); getch(); Open_File();// mo file F_Init_List(&Header_List_Ptr,&Tailer_List_Ptr); F_Make_List_Display(&Header_List_Ptr,&Tailer_List_Ptr); // tao danh sach last o vi tri cuoi puts("\PRINT LIST PRE PROCESSING ..."); puts("HIT ANY KEY..."); getch(); Print_List(Header_List_Ptr); //in danh sach moc noi ra man hinh puts("\HIT ANY KEY..."); puts("HAPPY OK! OK!...") ; getch(); F_Processcing_List(&Header_List_Ptr,&Tailer_List_Ptr); // su li danh sach //chay den day puts("LIST AFTER PROCESSING..."); puts("HIT ANY KEY..."); getch(); Print_List(Header_List_Ptr); puts("HIT ANY KEY..."); getch(); puts(" DISPLAY..."); getch(); puts("HIT ANY KEY..."); Display_Decode(&Header_List_Ptr,&Tailer_List_Ptr);// ham hien thi outtextxy(40,40,"FREE LIST....."); outtextxy(40,60,"HIT ANY KEY..."); getch(); Free_List(&Header_List_Ptr,&Tailer_List_Ptr);//giai phong bo nho clrscr(); outtextxy(40,40,"CLOSE GRAPHICS...."); outtextxy(40,60,"HIT ANY KEY......."); getch(); clrscr(); closegraph();//dong do hoa } //-------------------------------------------------------------------- void Input_Char_File_Name(void) { char ch; bool ok;//Char_File_Name la bien toan cuc do { puts("FILE NAME?..."); puts("LENTH OF FILE NAME <=25! "); gets(Char_File_Name); if( ( (strlen(Char_File_Name)==0) || (strlen(Char_File_Name)>25) ) ) ok=false; else ok=true; if (ok==false) { puts (" FILE NAME ERROR!... "); puts("HIT ANY KEY!..."); puts("HIT ESC TO EXIT...."); ch=getch(); if(ch==27) exit(0) ; else ok=false; } else { puts("FILE NAME SUCCESS! ..."); puts("HIT ANY KEY!..."); getch(); } } while( ok==false);//lap cho den khi nhap ten file dung } //---------------------------------------------------------------- void Open_File() { FILE *fp; //con tro file bool ok; UINT8 Test_Read_Fileformatarray[2]; char ch; do { puts("NOW! REOPEN THIS FILE..."); puts("HIT ANY KEY..."); getch(); Input_Char_File_Name();//nhap ten file puts(" FILE NAME... "); puts( Char_File_Name); getch(); fp = fopen(Char_File_Name,"rb");//mo tep doc kieu nhi phan if (fp==NULL) { ok=false; puts("FILE BLANK.... " ); puts("HIT ANY KEY... LOOP "); getch(); } else { puts("FILE NOT BLANK! ..."); puts("HIT ANY KEY!..."); getch(); fread(Test_Read_Fileformatarray,1,2,fp); if( (Test_Read_Fileformatarray[0] == FORMAT0) && (Test_Read_Fileformatarray[1]==FORMAT1)) { ok = true; //dung dinh dang puts("VIEW FORMAT... " ); printf("\n VALUE1 %d ",int (Test_Read_Fileformatarray[0])); printf("\n VALUE2 %d ",int (Test_Read_Fileformatarray[1])); getch();//dung lai de xem } else ok = false; // sai dinh dang if(ok==true) { File_Ptr=fp; return; } else // khong dung dinh dang { puts("FORMAT ERROR..."); printf("\nWRONG FORMAT1 %d ",int (Test_Read_Fileformatarray[0])); printf("\nWRONG FORMAT2 %d",int (Test_Read_Fileformatarray[1])); puts("EXIT?......."); puts("HIT ESC TO EXIT..."); ch=getch(); if (ch==27) exit(0); } } } while(ok==false); } //------------------------------------- void Print_Data_In_File(void) { bool ok; getch(); do { Input_Char_File_Name();// nhap lai ten file /*mo file de quan sat noi dung file*/ File_Ptr=fopen(Char_File_Name,"rb"); //mo lai file de doc if (File_Ptr==NULL) // khong mo duoc { puts("COULD NOT OPEN THIS FILE..."); ok=false; puts("HIT ANY KEY ..."); getch(); } else // mo duoc { puts("THIS FILE OPENED SUCCESSFULLY ..."); puts("HIT ANY KEY..."); getch(); ok=true; } } while(ok==false); char ch; int num=0; // so cac phan tu doc tu tep puts("DATA IN THIS FILE ..."); puts("HIT ANY KEY..."); puts("BYTE OF FILE..."); while(!feof(File_Ptr)) { int Test_Read_File=fread(&ch,1,1,File_Ptr) ; if(Test_Read_File<0) { puts("COULD NOT READ THIS FILE..."); break; } num++; puts("BYTE READ ..."); printf(" %d ,", ch); } puts("HIT ANY KEY TO CONTINUE..."); getch(); puts("NUMBER BYTE OF FILE..."); printf("\n %d ,",num-1); fcloseall(); } //---------------------------------------- void Init_Graphics(void ) { int gr_drive; int gr_mode; gr_drive= VGA; gr_mode= VGAHI; initgraph(&gr_drive,&gr_mode,"F:\\TC\\BGI"); /* loi do hoa*/ if (graphresult()!=grOk)//loi do hoa { puts("MESSAGE..."); puts("GRAPHICS ERROR!..."); puts("HIT ANY KEY TO EXIT..."); getch(); //doi den khi go vao mot phim exit(0); // thoat }///end if /*khong loi*/ puts(" *************************************************** "); puts(" MESSAGE... "); puts(" HIT KEY <- TO VIEW LEFT... ");//cacthong diep puts(" HIT KEY -> TO VIEW RIGH... " ); puts(" HIT ESC EXIT... "); puts(" MUMMUM... "); puts(" OK... "); puts(" HIT OTHER KEY SCREEN WILL STILL STOP ..."); puts(" *************************************************** "); getch();//doi den khi go vao mot phim } //----------------------------------------- /*ham ve bit 1*/ void RC5_Draw_Bit1(int bitnum) { moveto((560-40*bitnum),200); linerel(0,-50); linerel(20,0); linerel(0,50); } //------------------------------------------------- void RC5_Draw_Bit0( int bitnum) /*ham nay ve bit0 cua chuan RC5*/ { moveto(( 540-40*bitnum),200); linerel(0,-50); linerel(20,0); linerel(0,50); } //--------------------------------------- UINT32 F_Con_Vert1(UINT8 bytelow,UINT8 bytehigh) { UINT32 DataWord = 0; DataWord |= (UINT32)bytehigh; DataWord = DataWord<<8; DataWord |= (UINT32)bytelow; return DataWord; } //------------------------------------------- UINT32 F_Con_Vert2(UINT8 x,UINT8 y,UINT8 z,UINT8 t)//tu byte thap den byte cao { UINT32 DataWord=0; DataWord|=(UINT32)t; DataWord=DataWord<<8; DataWord|=(UINT32)z; DataWord=DataWord<<8; DataWord|=(UINT32)y; DataWord=DataWord<<8; DataWord|=(UINT32)x; return DataWord; } //------------------------------------------------------ void RC5_Draw_Dataword(UINT32 RC5_DataWord) /*ham nay ve tu ma cua chuan RC5*/ { int i; char* namekeypressed;//ten phim nhan UINT8 command; //lenh command=RC5_DataWord&0x3f;//'0011'1111'quan tam den 6 bit command if (command ==0) namekeypressed="CHANNEL0"; else if (command ==1) namekeypressed="CHANNEL1"; else if (command ==2) namekeypressed="CHANNEL2"; else if (command ==3) namekeypressed="CHANNEL3"; else if (command ==4) namekeypressed="CHANNEL4"; else if (command ==5) namekeypressed="CHANNEL5"; else if (command ==6) namekeypressed="CHANNEL6"; else if (command ==7) namekeypressed="CHANNEL7"; else if (command ==8) namekeypressed="CHANNEL8"; else if (command ==9) namekeypressed="CHANNEL9"; else if (command ==12) namekeypressed="STANDBY"; else if (command ==16) namekeypressed="MASTER VOLUME + "; else if (command ==17) namekeypressed="MASTER VOLUME -"; else if (command ==18) namekeypressed="BRIGHNESS +"; else if (command ==19) namekeypressed="BRIGHNESS -"; else if (command ==50) namekeypressed="FAST REWIND"; else if (command ==52) namekeypressed="FAST RUN FORWARD"; else if (command ==53) namekeypressed="PLAY"; else if (command ==54) namekeypressed="STOP"; else if (command ==55) namekeypressed="RECORDING"; setbkcolor(BLACK); setcolor(DARKGRAY); rectangle(10,10,629,469); setcolor( LIGHTGREEN); rectangle(15,20,619,459); moveto(15,200); lineto(619,200); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); setcolor(MAGENTA); outtextxy(200,230,"RC5_DATAWORD"); outtextxy(200,270,"BI PHASE CODING"); setcolor( GREEN);///mau Green outtextxy(20,100,"2 start"); outtextxy(100,100,"1 toggle"); outtextxy(190,100,"5 address"); outtextxy(360,100 ,"6 command"); setcolor( LIGHTRED); moveto(20,145); lineto(100,145); moveto(20,145); lineto(25,142); moveto(20,145); lineto(25,148); moveto(100,145); lineto(95,148); moveto(100,145); lineto(95,142); line(20,140,20,150); line(100,140,100,150); //-------------------------------------- moveto(100,145); lineto(140,145); moveto(100,145); lineto(105,142); moveto(100,145); lineto(105,148); moveto(140,145); lineto(135,148); moveto(140,145); lineto(135,142); line(140,140,140,150); //----------------------------------- moveto(140,145); lineto(340,145); moveto(140,145); lineto(145,142); moveto(140,145); lineto(145,148); moveto(340,145); lineto(335,148); moveto(340,145); lineto(335,142); line(340,140,340,150); //-------------------------------------- moveto(340,145); lineto(580,145); moveto(340,145); lineto(345,142); moveto(340,145); lineto(345,148); moveto(580,145); lineto(575,148); moveto(580,145); lineto(575,142); line(580,140,580,150); setcolor(40); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1); outtextxy(200,290,"**************************** "); outtextxy(200,310,"HIT KEY <- TO VIEW LEFT... "); setcolor(30); outtextxy(200,330,"HIT KEY -> TO VIEW RIGH... "); setcolor(35); outtextxy(200,350,"HIT KEY_HOME TO GO HEADER LIST... "); setcolor(30); outtextxy(200,370,"HIT KEY_END GO TAILER LIST... "); setcolor(35); outtextxy(200,390,"HIT ESC TO EXIT..."); setcolor(40); outtextxy(200,410,"HIT OTHER KEY NO THING TO DO..."); setcolor(RED); setbkcolor(BLACK); for( i =13 ;i>=0; i--) { if ((RC5_DataWord>>i)&1 == 1) { RC5_Draw_Bit1(i); moveto((560-40*i),150); lineto((560-40*i-3),155); moveto((560-40*i),150); lineto((560-40*i+3),155); setcolor(GREEN ); outtextxy((555-40*i),210,"|1|"); setcolor(RED); } else { RC5_Draw_Bit0(i); moveto((560-40*i),200); lineto((560-40*i-3),195); moveto((560-40*i),200); lineto((560-40*i+3),195); setcolor(BLUE); outtextxy((555-40*i),210, "|0|" ); setcolor(RED); } } } //----------------------------------------------------- void REC_Draw_Bit(int x0,int y0,int Fill_pattern, int Fill_Color)/*ham nay ve tung bit cua chuan RECS 80*/ { moveto (x0,y0); linerel(0,-70); linerel(15,0); linerel(0,70); setfillstyle(Fill_pattern,Fill_Color); bar(x0,y0,x0+15,y0-70); } //-------------------------------------------------------------- void REC_Draw_Dataword(UINT32 REC_DataWord) /*ham nay ve tu ma cua chuan RECS80*/ { int i ; int x=20; int x01; int y01; int y=200; setbkcolor(BLACK); setcolor(YELLOW); moveto(20,200); lineto(620,200); setcolor(GREEN); rectangle(10,10,629,469); setcolor( LIGHTGREEN); rectangle(15,20,619,459); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1); outtextxy(200,270,"REC_DATAWORD"); outtextxy(200,290,"**************************** "); outtextxy(200,310,"HIT KEY <- TO VIEW LEFT... "); setcolor(30); outtextxy(200,330,"HIT KEY -> TO VIEW RIGH... "); setcolor(35); outtextxy(200,350,"HIT KEY_HOME TO GO HEADER LIST... "); setcolor(30); outtextxy(200,370,"HIT KEY_END GO TAILER LIST... "); setcolor(35); outtextxy(200,390,"HIT ESC TO EXIT..."); setcolor(40); outtextxy(200,410,"HIT OTHER KEY NO THING TO DO..."); setcolor(RED); setbkcolor(BLACK); setcolor(GREEN); REC_Draw_Bit(x,y,SLASH_FILL,RED); for( i =11 ;i>=0; i--) { if(((REC_DataWord >>i)&1)==1) { x01=x+23; y01=220; x+=50; REC_Draw_Bit(x,y,SLASH_FILL,RED); setcolor(GREEN); outtextxy(x01,y01,"|1|"); setcolor(RED); } else { x01=x+13; y01=220; x+=32; REC_Draw_Bit(x,y,SLASH_FILL,RED); setcolor(BLUE); outtextxy(x01,y01,"|0|"); setcolor(RED); } } } //--------------------------------------------------------------- void NEC_Draw_Bit(int x0,int y0,int width,int Fill_pattern, int Fill_Color)/*ham nay ve tung bit cua chuan NEC*/ { moveto (x0,y0); linerel(0,-50); linerel(width,0); linerel(0,50); setfillstyle(Fill_pattern,Fill_Color); bar(x0,y0,x0+width,y0-50); } //--------------------------------------------------- void NEC_Draw_Dataword(UINT32 NEC_DataWord) /*ham nay ve tu ma cua chuan NEC*/ { int i; int x=20; int y=200; int x01; int y01; setbkcolor(BLACK); setcolor(YELLOW); moveto(20,200); lineto(620,200); rectangle(10,10,629,469); setcolor( LIGHTGREEN); rectangle(15,20,619,459); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); outtextxy(200,250,"NEC_DATAWORD"); setcolor(45); outtextxy(200,290,"**************************** "); outtextxy(200,310,"HIT KEY <- TO VIEW LEFT... "); setcolor(30); outtextxy(200,330,"HIT KEY -> TO VIEW RIGH... "); setcolor(35); outtextxy(200,350,"HIT KEY_HOME TO GO HEADER LIST... "); setcolor(30); outtextxy(200,370,"HIT KEY_END GO TAILER LIST... "); setcolor(35); outtextxy(200,390,"HIT ESC TO EXIT..."); setcolor(40); outtextxy(200,410,"HIT OTHER KEY NO THING TO DO..."); setcolor(25); NEC_Draw_Bit(x,y,50,WIDE_DOT_FILL,RED); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1); setcolor(35); outtextxy(x,230,"LEADER"); setcolor(40); outtextxy(x+50,130,"HEADER"); x=x+75; setcolor(45); NEC_Draw_Bit(x,y,4,WIDE_DOT_FILL,RED); setcolor(RED); for( i =32 ;i!=0; i--) { if ((NEC_DataWord>>i)&1==1) { x01=x+9; y01=230; x=x+20; NEC_Draw_Bit(x,y,4,WIDE_DOT_FILL,RED); setcolor(GREEN); outtextxy(x01,y01,"1"); setcolor(RED); } else { x01=x+5; y01=230; x=x+12; setcolor(BLUE); NEC_Draw_Bit(x,y,4,WIDE_DOT_FILL,RED); outtextxy(x01,y01,"0"); setcolor(RED); } } } //--------------------------------------------- void F_Init_List(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr) { *Header_List_Ptr=NULL; *Tailer_List_Ptr=NULL; } //----------------------------------------------------------// void Insert_List(LIST** Header_List_Ptr,LIST **Tailer_List_Ptr,DISPLAY Node_Dis)//chen nut vao cuoi danh sach { LIST *Node_Ptr; Node_Ptr=(LIST*)malloc(1*sizeof (LIST)); if(Node_Ptr!=NULL) { Node_Ptr->node=Node_Dis;// dua du lieu Node_Ptr->prev=NULL;//gan bangNULL Node_Ptr->next=NULL;//gan bangNULL if(*Header_List_Ptr==NULL)//vi tri dau tien,danh sach rong { *Header_List_Ptr=Node_Ptr;//phan dau tien *Tailer_List_Ptr=Node_Ptr;//phan dau tien } else //vi tri thu hai, Header_List_Ptr,last la cac bien toan cuc { (*Tailer_List_Ptr)->next=Node_Ptr;//containptr sau last Node_Ptr->prev=(*Tailer_List_Ptr);//bo xung containptr sau last (*Tailer_List_Ptr)=Node_Ptr;//dich con tro last vi tri moi } } else { puts("COULD ALLOC MEMMORY..."); puts("HIT ANY KEY..."); getch(); return;// tro lai hm go } } //---------------------------------------------- void Free_List(LIST **Header_List_Ptr,LIST**Tailer_List_Ptr) //xuat phat tu dau danh sach { LIST *Temp_List_Ptr;//con tro toi dau danh sach if ((*Header_List_Ptr)==NULL) { puts("LIST EMPTY..."); puts("HIT ANY KEY..."); getch(); return; } //danh sach khac rong Temp_List_Ptr=*Header_List_Ptr; while( Temp_List_Ptr!=NULL)//Header_List_Ptr!=NULL { Temp_List_Ptr=(*Header_List_Ptr)->next;//dich Temp_List_Ptr free(*Header_List_Ptr);//giai phong vi tri truoc (*Header_List_Ptr)=Temp_List_Ptr;//gan vitri moi } *Header_List_Ptr= NULL;//giai phong con tro *Tailer_List_Ptr=NULL; } //--------------------------------------------------------- void F_Make_List_Display (LIST **Header_List_Ptr,LIST**Tailer_List_Ptr) //tra ve Header_List_Ptr va last la 2 bien global { DISPLAY Node_Dis; UINT8 Byte_Read; int Test_Read_File;// bien nay kiem tra xem co doc duoc file hay khong if (File_Ptr==NULL) //tep rong { puts("FILE EMPTY..."); puts("HIT ANY KEY TO EXIT..."); getch(); fclose(File_Ptr); getch(); exit(0) ; //tep rong }//tep khac rong while(!feof(File_Ptr))// vong lap thoat khi khong doc duoc tep ,va khong cap phat bo nho { Test_Read_File=fread(&Byte_Read,1,1,File_Ptr) ;//doc tep if (Test_Read_File<0)// khong doc duoc tep , thi khong cap phat bo nho { puts(" NOW...COULD OPEN THIS FILE"); puts ("HIT ANY KEY..."); getch(); break; } else //doc duoc tep { Node_Dis.data=Byte_Read;// dua vao cau truc puts("BYTE READ ..."); printf("\n%d",(int) Byte_Read); Node_Dis.pos=0;//gan pos Node_Dis.mode=0;// gan mode Insert_List(Header_List_Ptr,Tailer_List_Ptr,Node_Dis) ;//chen vao cuoi danh sach }//end else }// end while fclose(File_Ptr); // dong file }//end function //----------------------------------------------------- void Print_List(LIST *Header_List_Ptr) //in danh sach moc noi ra man hinh { LIST* Ptr_List; if (Header_List_Ptr==NULL) { puts("LIST EMPTY..."); puts("HIT ANY KEY TO EXIT...!"); getch(); exit(0); } Ptr_List=Header_List_Ptr;// lay phan tu dau tien puts(" DATA IN LIST..."); do { printf("\n%s%d%s%d%s%d"," mode ",int ((Ptr_List->node).mode)," data ",(Ptr_List->node).data," pos ",(Ptr_List->node).pos); Ptr_List=Ptr_List->next; //dich } while((Ptr_List->next)!=NULL); } //---------------------------------------- LIST* Get_Header_List(LIST* list) { LIST *Ptr_List =NULL; if(list==NULL) { puts("LIST EMPTY ..."); return(Ptr_List); } Ptr_List=list;// khoi dong while(Ptr_List->next!=NULL) { Ptr_List=Ptr_List->next; } return Ptr_List; } //---------------------------------------- LIST* Get_Tailer_List(LIST* list) { LIST *Ptr_List =NULL; if(list==NULL) { puts("LIST EMPTY ..."); return(Ptr_List); } Ptr_List=list; while(Ptr_List->prev!=NULL) { Ptr_List=Ptr_List->prev; } return Ptr_List; } //------------------------------------------------------- void F_Processcing_List(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr) //luon xuat phat tu dau danh sach { LIST*p,*q; UINT8 Test1, Test2; UINT8 Current_Mode;//bien chua mode hien tai bool ok; /*-----------------phan dau ------------*/ if (*Header_List_Ptr==NULL)//danh sach rong { puts ("LIST EMPTY..."); //chay den day roi puts ("HIT ANY KEY..."); getch(); //thoat luon exit(0); // thoat } //Header_List_Ptr khac NULL p=*Header_List_Ptr; Test1=(p->node).data; if (Test1!=255) // khong dung dinh dang dau tien { puts("Test1"); printf("\n %d ",int(Test1)); puts ("FORMAT1 ERROR..."); //chay den day roi puts("HIT ANY KEY..."); puts("EXIT OK!..."); getch(); Free_List(Header_List_Ptr,Tailer_List_Ptr);//giai phong bo nho exit(0);//sai byte xac dinh chuan dau tien } //dung byte cua chuan dau tien (p->node).mode=4; q=p->next; //dich con tro vi tri tiep//VI TRI THU HAI if (q==NULL) //rong { puts ("LIST ONE NODE..."); //chay den day roi puts("HIT ANY KEY..."); puts("EXIT OK..."); getch(); Free_List(Header_List_Ptr,Tailer_List_Ptr);//giai phong bo nho exit(0); // tro lai } Test2=(q->node).data; // khong rong kiem tra mode if ((Test2==64)||(Test2==65)||(Test2==66)) // dung 64,65,66 ok=true; // gan else ok=false; // sai if (ok==false) //sai byte dinh dang thu hai { puts(" Test2"); printf(" %d ",int (Test2)); puts("FORMAT2 ERROR... "); puts(" HIT ANY KEY..."); getch(); Free_List(Header_List_Ptr,Tailer_List_Ptr);//giai phong bo nho exit(0); } else//(ok==true) // dung chuan,xac lap curren mode theo hai vi tri dau tien { (q->node).mode=4; puts("Header_List_Ptr STANDARD..."); puts("RIGH STANDARD... "); puts("HIT ANY KEY"); getch(); switch (Test2)//ok=true, gan Current_Mode,pos { case 64: // chuan RC5 { puts(" RC5 STANDARD..."); puts ("HIT ANY KEY..."); getch(); Current_Mode=1;//Current_Mode (p->node).mode=4;//chuan (q->node).mode=4;//chuan break; } case 65: { puts(" REC STANDARD..."); puts ("HIT ANY KEY...."); getch(); Current_Mode=2; (p->node).mode=4;//chuan (q->node).mode=4;//chuan break; } case 66: { puts("NEC STANDARD....."); puts ("HIT ANY KEY...."); getch(); Current_Mode=3; (p->node).mode=4;//chuan (q->node).mode=4;//chuan break; }//end case }//end switch,lay duoc Current_Mode } //end if /*--------------------------------------------------------------------*/ p=q->next;// if( p==NULL) { puts ("LIST HAVE TWO NODE..."); //chay den day roi puts("HIT ANY KEY..."); puts("EXIT OK..."); getch(); Free_List(Header_List_Ptr,Tailer_List_Ptr);//giai phong bo nho exit(0); // tro lai } do //lap di lap lap theo curent mode { Test1=(p->node).data; // khong cuoi if (Test1==255) //lai xuat hien mot chuan moi ok=true; // gan lai ok else ok=false; // gan ok if(ok==true)//la 255 { q=p->next; if (q==NULL) return; Test2=(q->node).data; if((Test2==64)||(Test2==65)||(Test2==66)) { if (Test2==64) { Current_Mode=1; (p->node).mode=4; (q->node).mode=4; p=q->next; q=p; } else if (Test2==65) { Current_Mode=2; (p->node).mode=4; (q->node).mode=4; p=q->next; q=p; } else { Current_Mode=3; (p->node).mode=4; (q->node).mode=4; p=q->next; q=p; } } else //khac 64,65,66 { if(Current_Mode==1) { // (p->node).mode=Current_Mode; (p->node).pos=1; (p->node).pos=1; q=p->next; if (q==NULL) return; (q->node).mode=Current_Mode; (q->node).pos=2; }// else if(Current_Mode==2) {// (p->node).mode=Current_Mode;//gan mode (p->node).pos=1;//gan pos q=p->next; p=q; if (q==NULL) return; (q->node).mode=Current_Mode; (q->node).pos=2; } // else if(Current_Mode==3) { // (p->node).mode=Current_Mode;//gan mode (p->node).pos=1;//gan pos q=p->next; p=q; if (q==NULL) return; (q->node).mode=Current_Mode; (q->node).pos=2; p=q->next;//p tro vitr tiep theo q=p; if (p==NULL) return; (p->node).mode=Current_Mode;//gan mode (p->node).pos=3; q=p->next;//q tro vitri tiep theo p=q; if (q==NULL) return; (q->node).pos=4;//gan pos (q->node).mode=Current_Mode; } // }//end else }//end else else//khac 64,65,66(ok=false) { if(Current_Mode==1) { // (p->node).mode=Current_Mode; (p->node).pos=1; q=p->next; if (q==NULL) return; (q->node).mode=Current_Mode; (q->node).pos=2; }// else if(Current_Mode==2) {// (p->node).mode=Current_Mode;//gan mode (p->node).pos=1;//gan pos q=p->next; if (q==NULL) return ; (q->node).mode=Current_Mode; (q->node).pos=2; } // else if(Current_Mode==3) { // (p->node).mode=Current_Mode;//gan mode (p->node).pos=1;//gan pos q=p->next; if (q==NULL) return; (q->node).mode=Current_Mode; (q->node).pos=2; p=q->next;//p tro vitr tiep theo if (p==NULL) return; (p->node).mode=Current_Mode;//gan mode (p->node).pos=3; q=p->next;//q tro vitri tiep theo if (q==NULL) return; (q->node).pos=4;//gan po (q->node).mode=Current_Mode; } // p=q->next;//dich con tro } }while(q!=NULL); //end while }//end untion //----------------------------------------------- void Display_Decode(LIST**Header_List_Ptr,LIST**Tailer_List_Ptr)// ham nay hien thi { LIST *q,*r;// con tro duyet danh sach UINT8 bytehigh; UINT8 bytelow; UINT8 x,y,z,t; UINT32 dataword;//tu ma char ch;// ma phim bool ok; if (*Header_List_Ptr==NULL)//danh sach rong { puts ("LIST EMPTY..."); //chay den day roi puts("EXIT..."); puts("HIT ANY KEY"); getch(); exit(0); } //rakhoi last tro den vi tri cuoi puts("LIST NOT EMPTY..."); puts("INIT GRAPHICS..."); puts("HIT ANY KEY..."); getch(); Init_Graphics(); //khoi tao do hoa q = *Header_List_Ptr;// khoi dong con tro setbkcolor(BLACK); while(1) { if(kbhit()) { char ch; ch = getch(); ok = false; switch(ch) { case 71: //left { clrscr(); outtextxy(40,40," GO HEADER LIST ..."); outtextxy(40,60," HIT ANY KEY... "); getch(); q=*Tailer_List_Ptr; ok = true; break; } case 79: //left { clrscr(); outtextxy(40,40," GO TAILER LIST ... ..."); outtextxy(40,60," HIT ANY KEY... "); getch(); q=*Tailer_List_Ptr; ok = true; break; } case 75: //left { clrscr(); q = q->prev; if (q==NULL) { outtextxy(40,40," GO HEADER LIST ..."); outtextxy(40,60," HIT ANY KEY... "); getch(); q=*Tailer_List_Ptr; } ok = true; break; } case 77: //righ { clrscr(); q = q->next; if(q==NULL) { outtextxy(40,40," GO TAILER LIST ..."); outtextxy(40,60," HIT ANY KEY... "); getch(); q=*Header_List_Ptr; } ok = true; break; } case 27: { ok=false; break; } default: ok=true; }//end switch bar(0,0,639,479); if(ok == true) { switch ((q->node).mode) { case 1://RC5 { if ((q->node).pos ==1)//kiem tra pos { r=q->next; if(r==NULL) break; bytelow=(q->node).data; bytehigh=(r->node).data; } else//pos=2 { r=q->prev; if (r==NULL) break; bytelow=(r->node).data; bytehigh=(q->node).data; } dataword=F_Con_Vert1(bytelow,bytehigh); clrscr(); RC5_Draw_Dataword(dataword); break; } case 2://REC80 { if ((q->node).pos ==1) { r=q->next; if (r==NULL) break; bytelow=(q->node).data; bytehigh=(r->node).data; } else//pos=2 { r=q->prev; if (r==NULL) break; bytelow=(r->node).data; bytehigh=(q->node).data; } dataword=F_Con_Vert1(bytelow,bytehigh); clrscr(); REC_Draw_Dataword(dataword); break; } case 3://NEC { if((q->node).pos==1) { x=(q->node).data; r=q->next; if( r==NULL) break; y=(r->node).data; r=q->next; if( r==NULL) break; z=(r->node).data; r=q->next; if( r==NULL) break; t=(r->node).data; } else if((q->node).pos==2) { q=q->prev; if( q==NULL) break; x=(r->node).data; y=(q->node).data; r=q->next; if( r==NULL) break; z=(r->node).data; r=q->next; if( r==NULL) break; t=(r->node).data; } else if ((q->node).pos==3) { z=(q->node).data; r=q->next; if( r==NULL) break; t=(r->node).data; r=q->prev; if( r==NULL) break; z=(r->node).data; r=q->next; if( r==NULL) break; x=(r->node).data; } else if ((q->node).pos==4) { t=(q->node).data; r=q->prev; if( r==NULL) break; z=(r->node).data; r=r->prev; if( r==NULL) break; y=(r->node).data; r=r->next; if( r==NULL) break; x=(r->node).data; } dataword=F_Con_Vert2(x,y,z,t); clrscr(); NEC_Draw_Dataword( dataword); break; }//end case }//end switch }//endifok else return; }//end ifkbhit }//end while(1) }//endfu Caùc taøi lieäu tham khaûo. Kó thuaät vi söû lí (VAÊN THEÁ MINH chuû bieân ). Kó thuaät gheùp noái maùy tính ( taùc giaû NGO DIEÂN TAÄP). Kó thuaät truyeàn soá lieäu (NGUYEÃN HOÀNG SÔN chuû bieân ). Hoï vi ñieàu khieån 8051 (taùc giaû TOÁNG VAÊN ON). Caùc Website cuûa caùc haõng INTEL,ATMEL,KEIL vvv Lôøi môû ñaàu 1 Lôøi caûm ôn ! 2 Chöông1 :Toång quan veà ñeà  taøi toát nghieäp. 3 1.1. Noäi dung ñeà taøi thieát keá. 3 1.2. Yeâu caàu cuûa thieát keá. 3 1.3. Höôùng thieát keá cho ñeà taøi. 3 1.4.Nguyeân lyù hoaït ñoäng cuûa maïch. 4 1.5. Höôùng môû roäng cho ñeà taøi. 5 Chöông2:Cô sôû lí thuyeát. 7 2.1 .Toång quan veà moät soá heä thoáng ñieàu khieån töø xa: 7 2.2.Ñaïi cöông veà quang ñieän töû: 12 2.2.1.Led hoàng ngoaïi: 13 2.2.2.Hoàng ngoaïi gaàn: 14 2.2.3.Nguoàn phaùt saùng hoàng ngoaïi: 14 2.3.Moät soá chuaån ñieàu cheá maõ hoaõ duøng trong ñieàu khieån töø xa cuûa TI VI. 16 2.3.1. Chuaån RC5. 16 2.3.2. ChuÈn REC 17 2.3.3.Chuaån NEC 18 2.3.4. Mét sè ®Æc tÝnh kÜ thuËt cña TSOP18xx, vµ TSOP17xx. 19 2.4.Giao tieáp cuûa PC vôùi ngoaïi vi 19 2.4.1Giao tieáp qua Slot: 19 2.4.2.Giao tieáp qua coång noái tieáp: 21 2.4.2.1.Truyeàn ñoàng boä : 21 2.4.2.2.Truyeàn khoâng ñoàng boä: 21 2.4.2.3. GIÔÙI THIEÄU VEÀ GIAO DIEÄN NOÁI TIEÁP: 22 2.4.2.4. Baûng thoâng soá veà tính naêng kó thuaät cuaû giao dieän RS-232 / V 24 : 23 2.4.2.5.Vaøi neùt cô baûn veà coång noái tieáp: 24 2.4.2.5.1.Söï trao ñoåi cuûa ñöôøng daãn tín hieäu: 25 2.4.3.Giao tieáp qua Printer Port: 29 2.4.3.1.Vaøi neùt cô baûn veà coång gheùp noái vôùi maùy in: 29 Chöông 3 :Thieát keá cuï theå. 35 3.1.Thieát keá phaàn cöùng. 36 3.1.1. Khoái nguoàn cung caáp . 36 3.1.1.1.Sô ñoà maïch nguoàn. 36 3.1.1.2. Caùc thoâng soá cuûa IC: 36 3.1.1.3. Ñieän aùp ra : 37 3.1.1.4.Ñaëc tính cuûa IC : 37 3.1.2. Khoái xöû lyù trung taâm. 37 3.1.3. Khoái giao tieáp giöõa PC vaø khoái xöû lyù trung taâm 40 3.1.4.Khoái choïn mode . 42 3.1.5.Khoái maét nhaän. 42 3.2. Thieát keá phaàn meàm. 43 3.2.1. Thieát keá löu ñoà thuaät toaùn thu treân PC vaø thay ñoåi cheá ñoä giaûi maõ töø PC. 43 3.2.2.Chöông trình giaûi maõ,hieån thò treân PC: 44 3.2.2.Thuaät toaùn treân khoái xöû lí trung taâm. 62 3.2.2.1.Thuaät toaùn ñeå nhaän daïng töø maõ chuaån RC5. 62 3.2.2.2.Thuaät toaùn nhaän daïng cho caùc töø maõ chuaån REC. 64 3.2.2.3.Thuaät toaùn nhaän daïng töø maõ cho chuaån NEC. 65 3.2.2.4.Thuaät toaùn caùc haøm coù nhieäm vuï truyeàn veà PC, nhaän döõ lieäu töø PC. 67 3.2.2.5.Thuaät toaùn cho haøm Main treân Vi ñieàu khieån. 69 Chöông 4:Keát luaän. 71 4.1 Ñaùnh giaù heä thoáng. 71 4.2.Phöông aùn khaéc phuïc vaø naâng caáp . 72 Phaàn 2 : Phuï luïc. 74 Phuï luïc A :Giôùi thieäu veà caùc linh kieän söû duïng trong ñoà aùn . 74 1.1. Vi ñieàu khieån hoï MCS -51 74 1.2 Vi ñieàu khieån AT89C52 75 1.2.1. Caáu taïo chaân 76 1.2.2. Sô ñoà khoái 77 1.2.3. Moâ taû chöùc naêng cuûa caùc chaân 78 1.2.4. Caùc thanh ghi chöùc naêng (SFR-Special Funtion Reisters) 79 1.2.5. Boä nhôù döõ lieäu 82 1.2.6. Ñaëc tính boä dao ñoäng 82 1.2.7. Cheá ñoä löôøi 83 1.2.8. Cheá ñoä haï nguoàn 83 1.2.9. Traïng thaùi cuûa moät soá chaân trong cheá ñoä löôøi vaø cheá ñoä haï nguoàn 84 1.2.10. Caùc thoâng soá kyõ thuaät 84 1.2.11. Hoaït ñoäng cuûa port noái tieáp 87 1.2.11.1Khaùi quaùt veà port noái tieáp: 87 1.2.11.2. Cheá ñoä thanh ghi dòch 8 bit . 88 1.2.11.3. Cheá ñoä UART 8 bit. 89 1.2.11.3. UART 9 bit: toác ñoä baud coá ñònh. 89 1.2.11.4. UART 9-bit: toác ñoä baud thay ñoåi. 90 1.2.11.5. Toác ñoä baud cuûa port noái tieáp . 90 1.2.12.Ngaét –vai troø cuûa ngaét trong caùc öùng duïng cuûa boä vi ñieàu khieån. 90 1.2.12.1.Sô löôïc veà ngaét. 90 1.2.12.2.Toå chöùc ngaét cuûa hoï 8051. 91 1.2.12.3.Cho pheùp vaø khoâng cho pheùp ngaét. 91 1.2.12.1.Öu tieân ngaét . 92 1.2.12.5.Chuoãi voøng . 92 1.2.12.6.Trình töï söû lyù ngaét . 93 1.2.12.7.Caùc vector ngaét . 93 1.2.13.Hoaït ñoäng ñònh thôøi cuûa 8501. 94 1.2.13.1.Toång quaùt veà ñònh thôøi . 94 1.2.13.2.ÖÙng duïng cuûa boä ñònh thôøi . 94 1.2.13.2.1.Ñònh thôøi moät khoaûng thôøi gian . 94 1.2.13.2.2. Ñeám söï kieän. 94 1.2.13.3.Thanh ghi cheá ñoä ñònh thôøi (TMOD) 95 Bít 95 1.2.13.1.Thanh ghi ñieàu khieån ñònh thôøi(TCON). 95 1.2.13.5.Caùc cheá ñoä hoaït ñoäng cuûa boä ñònh thôøi. 96 1.2.13.5.1.Cheá ñoä ñònh thôøi 13-bit. 96 1.2.13.5.2.Cheá ñoä ñònh thôøi 16-bit. 96 1.2.13.5.3.Cheá ñoä töï naïp 8-bit. 96 1.2.13.5.1.Cheá ñoä ñònh thôøi chia seû . 97 1.3.1. Caáu taïo chaân 98 1.3.2. Moâ taû chöùc naêng chaân 98 1.3.3. Sô ñoà khoái vaø maïch tieâu bieåu 99 Phuïluïc B :Maõ nguoàn chöông trình 101 1.Maõ nguoàn chöông trình treân khoái söû lí trung taâm. 101 2. Maõ nguoàn chöông trình thu treân PC. 107 3.chöông trình giaûi maõ hieån thò treân PC 112 Caùc taøi lieäu tham khaûo. 133

Các file đính kèm theo tài liệu này:

  • docDAN081.doc