Cp120x uart test
/*
* PIC18F4550 UART example
* Written by: BENCHEROUDA Okba
* E-mail: electronnote@gmail.com
* Website: http://elecnote.blogspot.com/
* Internal oscillator used at 8MHz
* Use at your own risk
*/
//perfect code
#define Led PORTB.F1
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
char Uart_Rd;
char * Op="HELLO TESTING";
char * Dl="ok";
int St[15],Lcd[15];
char i,j,k ;
void main() {
OSCCON = 0X70; // Set internal oscillator to 8MHz
ADCON1 = 0x0F; // Configure AN pins as digital
CMCON = 7; // Disable comparators
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1," Uart Under Teat");
UART1_Init(9600); // Initialize USART module
// (8 bit, 19200 baud rate, no parity bit...)
delay_ms(200);
UART1_Write_Text("Hello world!");
delay_ms(1000);
UART1_Write(13); // Start a new line
UART1_Write(10);
UART1_Write_Text("PIC18F4550 UART example");
UART1_Write(13); // Start a new line
UART1_Write(10);
delay_ms(1000);
while (1) { // Endless loop
if (UART1_Data_Ready())
{ // If data has been received
i = UART1_Read(); // read it
UART1_Write(i); // and send it back
IntToStr(i,St);
j=0;
for(k=0;k<=15;k++)
{
if(St[k]!=' ')
{
Lcd[k]=St[k];
j++;
}
}
Lcd_Out(2,1,St);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
// UART1_Write(13); // Start a new line
// UART1_Write(10);
// UART1_Write(12);
}
}
Cp120x need to install driver.And you can use arduino ide or mikroc pro or any other ide with terminal emulator.
https://youtu.be/tUP3T8ffh3E
Comments
Post a Comment