Created
April 28, 2011 02:08
-
-
Save hkulekci/945657 to your computer and use it in GitHub Desktop.
CCS Code RS232 Simulation for Rf Communication on Proteus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <16f877.h> | |
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD | |
#use delay (clock=4000000) | |
#use fast_io(b) | |
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7,) | |
#define use_portb_lcd TRUE | |
#include <lcd.c> | |
#define CLIENT_NO '1' | |
#define MAXCHAR 64 | |
#define BLANKCHARACTER ' ' | |
#define LCDSIZEX 16 | |
#define LCDSIZEY 2 | |
char coming[MAXCHAR]; | |
void charinit(){ | |
int i; | |
for (i = 0;i < MAXCHAR;i++){ | |
coming[i] = BLANKCHARACTER; | |
} | |
} | |
void lcd_clear(){ | |
printf(lcd_putc,"\f");} | |
int printToLCD(char *readed,int *row, int *column,int *page){ | |
lcd_gotoxy(*column,*row); | |
if(*readed != BLANKCHARACTER){ | |
*column = (int8)*column + 1; | |
if (*column > LCDSIZEX){ | |
*row = (int8)*row + 1; | |
*column = 1; | |
} | |
if (*row > LCDSIZEY){ | |
*column = 1; | |
*row = 1; | |
lcd_clear(); | |
*page = (int8)*page + 1; | |
} | |
printf(lcd_putc, "%c", *readed); | |
} | |
return 1; | |
} | |
void main(void) | |
{ | |
char x; | |
int row=1,column=1,page=0; | |
int numOfcomingData = 0, read_to_message = 0; | |
int last_message = 0; | |
lcd_init(); | |
while(1) | |
{ | |
do{ | |
x = getc(); | |
}while(x == BLANKCHARACTER); | |
if (last_message == 1){ | |
lcd_clear(); | |
last_message = 0; | |
} | |
if (numOfcomingData <= 4 && x != BLANKCHARACTER){ | |
putc(x); | |
//printToLCD(&x,&row,&column,&page); | |
//printf(lcd_putc,"%c",x); | |
coming[numOfcomingData] = x; | |
numOfcomingData++; | |
} | |
if (read_to_message == 1 && x != BLANKCHARACTER){ | |
putc(x); | |
//printToLCD(&x,&row,&column,&page); | |
//printf(lcd_putc,"%c",x); | |
coming[numOfcomingData] = x; | |
numOfcomingData++; | |
} | |
if (coming[0] == 'h' && coming[1] == 'o' | |
&& coming[2] == 'c' && coming[3] == 'a' | |
&& coming[4] == CLIENT_NO){ | |
read_to_message = 1; | |
} | |
if(x == '|'){ | |
coming[0]=BLANKCHARACTER; | |
coming[1]=BLANKCHARACTER; | |
coming[2]=BLANKCHARACTER; | |
coming[3]=BLANKCHARACTER; | |
coming[4]=BLANKCHARACTER; | |
read_to_message = 0; | |
last_message = 1; | |
numOfcomingData = 0; | |
charinit(); | |
row=0; | |
column=0; | |
page=0; | |
} | |
x = ' '; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <16f877.h> | |
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD | |
#use delay (clock=4000000) | |
#use fast_io(a) | |
#use fast_io(b) | |
#use fast_io(c) | |
#use fast_io(d) | |
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7,) | |
#define use_portb_lcd TRUE | |
#include <lcd.c> | |
//Satýrlar | |
#define sat1 pin_d0 | |
#define sat2 pin_d1 | |
#define sat3 pin_d2 | |
#define sat4 pin_d3 | |
#define sat5 pin_d4 | |
#define sat6 pin_d5 | |
//Sütunlar | |
#define sut1 pin_a0 | |
#define sut2 pin_a1 | |
#define sut3 pin_a2 | |
#define sut4 pin_a3 | |
#define sut5 pin_a4 | |
#define sut6 pin_a5 | |
#define sut7 pin_e0 | |
#define LCDSIZEX 16 | |
#define LCDSIZEY 2 | |
#define MAXCHAR 64 | |
#define BLANKCHARACTER ' ' | |
char willBeSent[MAXCHAR] = {}; | |
char oku() | |
{ | |
output_high(sat1); | |
if (input(sut1)) | |
{delay_ms(200); return 'A'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'B'; } | |
if (input(sut3)) | |
{delay_ms(200); return 'C'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'D'; } | |
if (input(sut5)) | |
{delay_ms(200); return '1'; } | |
if (input(sut6)) | |
{delay_ms(200); return '2'; } | |
if (input(sut7)) | |
{delay_ms(200); return '3'; } | |
output_low(sat1); | |
output_high(sat2); | |
if (input(sut1)) | |
{delay_ms(200); return 'E'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'F';} | |
if (input(sut3)) | |
{delay_ms(200); return 'G'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'H'; } | |
if (input(sut5)) | |
{delay_ms(200); return '4'; } | |
if (input(sut6)) | |
{delay_ms(200); return '5'; } | |
if (input(sut7)) | |
{delay_ms(200); return '6'; } | |
output_low(sat2); | |
output_high(sat3); | |
if (input(sut1)) | |
{delay_ms(200); return 'I'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'J'; } | |
if (input(sut3)) | |
{delay_ms(200); return 'K'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'L'; } | |
if (input(sut5)) | |
{delay_ms(200); return '7'; } | |
if (input(sut6)) | |
{delay_ms(200); return '8'; } | |
if (input(sut7)) | |
{delay_ms(200); return '9'; } | |
output_low(sat3); | |
output_high(sat4); | |
if (input(sut1)) | |
{delay_ms(200); return 'M'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'N'; } | |
if (input(sut3)) | |
{delay_ms(200); return 'O'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'P'; } | |
if (input(sut5)) | |
{delay_ms(200); return '?'; } | |
if (input(sut6)) | |
{delay_ms(200); return '0'; } | |
if (input(sut7)) | |
{delay_ms(200); return '.'; } | |
output_low(sat4); | |
output_high(sat5); | |
if (input(sut1)) | |
{delay_ms(200); return 'R'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'S'; } | |
if (input(sut3)) | |
{delay_ms(200); return 'T'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'U'; } | |
if (input(sut5)) | |
{delay_ms(200); return 'V'; } | |
if (input(sut6)) | |
{delay_ms(200); return 'Y'; } | |
if (input(sut7)) | |
{delay_ms(200); return 'b'; } | |
output_low(sat5); | |
output_high(sat6); | |
if (input(sut1)) | |
{delay_ms(200); return 'Z'; } | |
if (input(sut2)) | |
{delay_ms(200); return 'Q'; } | |
if (input(sut3)) | |
{delay_ms(200); return 'X'; } | |
if (input(sut4)) | |
{delay_ms(200); return 'W'; } | |
if (input(sut5)) | |
{delay_ms(200); return '_' ; } | |
if (input(sut6)) | |
{delay_ms(200); return 'a'; } | |
if (input(sut7)) | |
{delay_ms(200); return ','; } | |
output_low(sat6); | |
return BLANKCHARACTER; | |
} | |
void lcd_clear(){ | |
printf(lcd_putc,"\f");} | |
void charinit(){ | |
int i; | |
for (i = 0;i < MAXCHAR;i++){ | |
willBeSent[i] = BLANKCHARACTER; | |
} | |
} | |
void sendToRS232(){ | |
int i; | |
for (i = 0;i < MAXCHAR ;i++){ | |
putc(willBeSent[i]); | |
} | |
} | |
int printToLCD(char *readed,int *row, int *column,int *page){ | |
if (*readed == 'b'){ | |
*column = (int8)*column - 1; | |
if (*column < 1){ | |
*row = (int8)*row - 1; | |
*column = LCDSIZEX; | |
if (*row < 1){ | |
*row = 1; | |
*column = 1; | |
} | |
} | |
*readed = BLANKCHARACTER; | |
lcd_gotoxy(*column,*row); | |
printf(lcd_putc, "%c", *readed); | |
return 0; | |
} | |
lcd_gotoxy(*column,*row); | |
if(*readed != BLANKCHARACTER){ | |
*column = (int8)*column + 1; | |
if (*column > LCDSIZEX){ | |
*row = (int8)*row + 1; | |
*column = 1; | |
} | |
if (*row > LCDSIZEY){ | |
*column = 1; | |
*row = 1; | |
lcd_clear(); | |
*page = (int8)*page + 1; | |
} | |
printf(lcd_putc, "%c", *readed); | |
} | |
return 1; | |
} | |
int select_client(char h){ | |
if (h == '1'){ | |
return 1; | |
}else if (h == '2') | |
return 2; | |
else if (h == '3') | |
return 3; | |
else | |
return 0; | |
} | |
void main ( ) | |
{ | |
char readed; | |
int column=1,row=1; | |
int numberOfCharacters = 0; | |
int result = 0; | |
int page = 0; | |
set_tris_d(0b00000000); | |
set_tris_a(0b00111111); | |
set_tris_e(0b00000001); | |
lcd_init(); | |
while(1) | |
{ | |
lcd_clear(); | |
delay_ms(100); | |
// Client Selection start | |
printf(lcd_putc,"Num of Client"); | |
lcd_gotoxy(0,2); | |
printf(lcd_putc,"[1-2-3]:"); | |
do{ | |
delay_ms(100); | |
readed = oku(); | |
if (select_client(readed) == 0 && readed != BLANKCHARACTER){ | |
lcd_clear(); | |
printf(lcd_putc,"Error!"); | |
delay_ms(500); | |
lcd_clear();printf(lcd_putc,"Num of Client"); | |
lcd_gotoxy(0,2); | |
printf(lcd_putc,"[1-2-3]:"); | |
readed = BLANKCHARACTER; | |
continue; | |
} | |
}while(readed == BLANKCHARACTER); | |
lcd_clear(); | |
//hocanibilgi[4] = readed; | |
//willBeSentChar(hocanibilgi); | |
putc('h'); | |
putc('o'); | |
putc('c'); | |
putc('a'); | |
putc(readed); | |
printf(lcd_putc,"%c. hoca secildi",readed); | |
// sending client information to rs232 | |
//sendToRS232(); | |
delay_ms(300); | |
// Client Selection end | |
// Sent To client first information | |
lcd_clear(); | |
readed = BLANKCHARACTER; | |
charinit();// willBeSentler dizisini bosaltiyor | |
printf(lcd_putc,"Number: "); | |
delay_ms(100); | |
row = 1; | |
column = 8; | |
while(1){ | |
readed = BLANKCHARACTER; | |
result = 0; | |
do{ | |
delay_ms(100); | |
readed = oku(); | |
}while(readed == BLANKCHARACTER); | |
if (row <= 1 && column < 8 && page == 0 ) column = 8; | |
if(readed == 'a'){ | |
sendToRS232(); | |
break; | |
} | |
result = printToLCD(&readed,&row,&column,&page); | |
if (result == 1){ | |
if (numberOfCharacters >= MAXCHAR){ | |
numberOfCharacters = 0; | |
} | |
willBeSent[numberOfCharacters++] = readed; | |
}else{ | |
willBeSent[--numberOfCharacters] = readed; | |
} | |
} | |
// Sent To client first information is ending | |
putc('!'); | |
// Message | |
lcd_clear(); | |
readed = BLANKCHARACTER; | |
charinit();// wilbesent array is reset | |
numberOfCharacters = 0; | |
printf(lcd_putc,"Mess: "); | |
delay_ms(100); | |
row = 1; | |
column = 6; | |
while(1){ | |
readed = BLANKCHARACTER; | |
result = 0; | |
do{ | |
delay_ms(100); | |
readed = oku(); | |
}while(readed == BLANKCHARACTER); | |
if (row <= 1 && column < 6 && page == 0) column = 6; | |
if(readed == 'a'){ | |
sendToRS232(); | |
break; | |
} | |
result = printToLCD(&readed, &row, &column, &page); | |
if (result == 1){ | |
if (numberOfCharacters >= MAXCHAR){ | |
numberOfCharacters = 0; | |
} | |
willBeSent[numberOfCharacters++] = readed; | |
}else{ | |
willBeSent[--numberOfCharacters] = readed; | |
} | |
} | |
// son ogrenci mesaji | |
putc('|'); | |
///// Last Message ///// | |
lcd_clear(); | |
printf(lcd_putc,"message is sent."); | |
lcd_gotoxy(0,2); | |
printf(lcd_putc,"(kulekci)"); | |
delay_ms(750); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment