wa'id
Junior Member level 1
I was reading data from USART Terminal into PIC in proteus, buh UART_Read() only reads like first bit of whatever input data and ignores others. Please how do I read the whole data into my PIC..I use mikrobasic
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
while (TRUE) ' Endless loop
if (UART1_Data_Ready() <> 0) then ' If data is received,
uart_rd = UART1_Read() ' read the received data,
UART1_Write(uart_rd)
Lcd_Ch(uart_rd) ' and send data via UART
end if
wend
main()
{
unsigned char ch;
---------------
---------------
ch=UART_read();
---------
}
unsigned char UART_read()
{
unsigned char ch;
CREN=1;
uart_wait();
ch=RCREG;
return ch;
}
void uart_wait()
{
unsigned char ch;
if(!OREE)
CREN=0;
ch=RCREG;
CREN=1;
while(!RCIF) //Continue until you receive a byte from transmitter.
continue;
}
Code Basic4GL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 program UART_project dim uart_rd as word dim LCD_RS as sbit at RB4_bit dim LCD_EN as sbit at RB5_bit dim LCD_D7 as sbit at RB3_bit dim LCD_D6 as sbit at RB2_bit dim LCD_D5 as sbit at RB1_bit dim LCD_D4 as sbit at RB0_bit dim LCD_RS_Direction as sbit at TRISB4_bit dim LCD_EN_Direction as sbit at TRISB5_bit dim LCD_D7_Direction as sbit at TRISB3_bit dim LCD_D6_Direction as sbit at TRISB2_bit dim LCD_D5_Direction as sbit at TRISB1_bit dim LCD_D4_Direction as sbit at TRISB0_bit dim output as char[1] main: TRISB = 0 PORTB = %11111111 ANSEL = 0 ANSELH = 0 Lcd_init() Lcd_Cmd(_LCD_CLEAR) UART1_Init(9600) ' Initialize UART module at 9600 bps Delay_ms(100) ' Wait for UART module to stabilize while (TRUE) ' Endless loop if (UART1_Data_Ready() <> 0) then ' If data is received, uart_rd = UART1_Read() ' read the received data, UART1_Write(uart_rd) ByteToStr(uart_rd,output) Lcd_Out_Cp(output) ' and send data via UART end if wend end
Try this.
Code:main() { unsigned char ch; --------------- --------------- ch=UART_read(); --------- } unsigned char UART_read() { unsigned char ch; CREN=1; uart_wait(); ch=RCREG; return ch; } void uart_wait() { unsigned char ch; if(!OREE) CREN=0; ch=RCREG; CREN=1; while(!RCIF) //Continue until you receive a byte from transmitter. continue; }
Try this code and inform us if you get any error.