Home › Forums › Microcontrollers › PIC Microcontroller › LCD and UART PIC Microcontroller
- This topic has 5 replies, 2 voices, and was last updated 9 years, 11 months ago by Ligo George.
-
AuthorPosts
-
December 9, 2014 at 1:00 pm #10165IvanParticipant
I’m trying send data to the PIC using the Terminal Window on Proteus, but something is wrong and I don’t understand why. I attached the Proteus project and *.HEX.
The PIC is 16F628a.
#define _XTAL_FREQ 8000000 #define RS RB0 #define EN RB3 #define D4 RB4 #define D5 RB5 #define D6 RB6 #define D7 RB7 #include <xc.h> #include "lcd.h" #include "uart.h" #pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD) #pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled) #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) void main() { TRISB = 0b000000110; TRISA0 = 0; Lcd_Init(); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("WAITING..."); UART_Init(9600); UART_Write_Text("Terminal is running!"); while(1) { if(UART_Data_Ready()) { Lcd_Clear(); RA0 = 1; Lcd_Write_String(UART_Read_Text); __delay_ms(1000); } } }
The UART.h and LCD.h from https://electrosome.com/lcd-pic-mplab-xc8/ and https://electrosome.com/uart-pic-microcontroller-mplab-xc8/
Somebody know why the code is not working?
December 9, 2014 at 2:09 pm #10168Ligo GeorgeKeymasterHello,
Use this program :void main() { TRISB = 0b000000110; TRISA0 = 0; Lcd_Init(); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("WAITING..."); UART_Init(9600); UART_Write_Text("Terminal is running!"); Lcd_Set_Cursor(2,1); while(1) { if(UART_Data_Ready()) { RA0 = 1; Lcd_Write_Char(UART_Read()); __delay_ms(300); } } }
December 9, 2014 at 2:26 pm #10169IvanParticipantWorking fine! Thank you 🙂
December 12, 2014 at 2:44 am #10218IvanParticipantNow I’m testing something new.
if(UART_Data_Ready()) { switch(UART_Read()) { case 0x0D: // Enter Lcd_Clear(); break; case 0x61: Lcd_Write_Char('a'); break; default: Lcd_Write_Char(UART_Read()); break; }
When I press ‘a’ the letter is added automatically, or when when i press ‘Enter’ the lcd clears itself. but when I want add another letter a need to press twice. Do you know why?
Maybe I need do create a case for every letter.
December 12, 2014 at 4:02 am #10219IvanParticipantIgnore my last reply. I solved.
December 12, 2014 at 9:32 am #10220Ligo GeorgeKeymasterOK, fine.
-
AuthorPosts
- You must be logged in to reply to this topic.