LCD and UART PIC Microcontroller

Home Forums Microcontrollers PIC Microcontroller LCD and UART PIC Microcontroller

Tagged: , , , ,

This topic contains 5 replies, has 2 voices, and was last updated by  Ligo George 2 years, 8 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10165

    Ivan
    Participant

    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?

    Attachments:
    You must be logged in to view attached files.
    #10168

    Ligo George
    Keymaster

    Hello,
    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);
        }
      }
    }
    
    #10169

    Ivan
    Participant

    Working fine! Thank you 🙂

    #10218

    Ivan
    Participant

    Now 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.

    #10219

    Ivan
    Participant

    Ignore my last reply. I solved.

    #10220

    Ligo George
    Keymaster

    OK, fine.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

string(7) "9898001"