Created
February 2, 2020 10:48
-
-
Save gresan-gits/a3bf214ae15a948c9e5c542eeb8376f9 to your computer and use it in GitHub Desktop.
CCS RS232
This file contains hidden or 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 <18F4520.h> | |
#FUSES NOWDT //No Watch Dog Timer | |
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale | |
#FUSES HS //High speed Osc (> 4mhz FOR PCM/PCH) (>10mhz for PCD) | |
#FUSES NOBROWNOUT //No brownout reset | |
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used FOR I/O | |
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) | |
#use delay(clock=12000000) | |
#use rs232(FORCE_SW,baud=4800,parity=N,xmit=PIN_B3,rcv=PIN_B4,bits=8,stream=UART_MEM,errors) | |
#use rs232(UART1,baud=9600,parity=N,stream=UART_CUNG,errors) | |
#include <string.h> | |
char c ,d; | |
int i=20; | |
char x='A'; | |
char chuoi[]="Xin chao"; | |
void xuat(VOID) | |
{ | |
fputc ('C', UART_CUNG); | |
fputc (13, UART_CUNG); | |
fputs ("Huong dan giao tiep rs 232Cung", UART_CUNG) ; | |
delay_ms (1000); | |
} | |
void xuat2(VOID) | |
{ | |
fputc ('M',UART_MEM); | |
fputc (13,UART_MEM); | |
fputs ("Xuat gia tri ra cong RS232 Mem", UART_MEM) ; | |
delay_ms (1000); | |
} | |
void test_doc(VOID) | |
{ | |
c = fgetc (UART_CUNG) ; | |
IF (c == 'a') | |
{ | |
output_high (PIN_D0); | |
} | |
ELSE | |
{ | |
output_low (PIN_D0); | |
} | |
d = getc (); | |
IF (c == 'b') | |
{ | |
output_high (PIN_D1); | |
} | |
ELSE | |
{ | |
output_low (PIN_D1); | |
} | |
} | |
void main() | |
{ | |
setup_timer_3 (T3_DISABLED|T3_DIV_BY_1); | |
WHILE (TRUE) | |
{ | |
// fprintf(UART_CUNG,"Chuoi xuat boi-frintf-\n\r"); | |
// fprintf(UART_MEM,"Chuoi xuat boi\"frintf\"\n\r"); | |
// delay_ms(1000); | |
fprintf(UART_CUNG,"CUNG_Gia tri cua i=%u \n\r",i); | |
fprintf(UART_MEM,"MEM_Gia tri cua x =%c \n\r",x); | |
fputc ('D',UART_MEM); | |
//fprintf(UART_CUNG,"CUNG_Gia tri cua x=%c \n\r",chuoi[4]); | |
fprintf(UART_MEM,"MEM_Gia tri cua chuoi =%s \n\r",chuoi); | |
delay_ms(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment