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
Create two ports using Elitma and then check whether they are working or not..
Open MikroBasic USART Terminal and then Set com port to the desired com port and then connect proteus com pim to virtual terminal..
Then check whether your communication part is okay or not...
Getting data from USART Terminal to proteus is not the issue as this is perfectly working. The issue is "Reading the data into PIC". Fine, I used UART_Read() in my code to read the data into a variable buh it doesn't work correctly. It only read the first bit of the data ie only a 1 (high) is displayed on the oscilloscope i use to check the data.
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
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 stabilizewhile(TRUE)' Endless loopif(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 UARTendifwendend
.
---------- Post added at 23:33 ---------- Previous post was at 23:29 ----------
You have to use UART1_Read_Text() to read strings. UART1_Read() only reads one char at a time. if you want to use UART1_Read() and you are receiving a string of 12 characters then you have to make a loop from 0 to 11 and read 1 char at a time and put it in an array and finally display the array on lcd.