Giúp uart và lcd với mikroc

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • muatuyet_2012
    Nhập môn đệ tử
    • Apr 2010
    • 6

    #1

    Giúp uart và lcd với mikroc

    Mình muốn truyền một kí tự từ máy tính xuống lcd nhưng nó bị lỗi và mình ko biết phải sửa như thế nào cả.
    Mong các bạn giúp đỡ.
    Đây là code của mình.
    Mình viết bằng trình biên dịch Mikroc.

    // LCD module connections
    sbit LCD_RS at RB4_bit;
    sbit LCD_EN at RB5_bit;
    sbit LCD_D4 at RB0_bit;
    sbit LCD_D5 at RB1_bit;
    sbit LCD_D6 at RB2_bit;
    sbit LCD_D7 at RB3_bit;

    sbit LCD_RS_Direction at TRISB4_bit;
    sbit LCD_EN_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB0_bit;
    sbit LCD_D5_Direction at TRISB1_bit;
    sbit LCD_D6_Direction at TRISB2_bit;
    sbit LCD_D7_Direction at TRISB3_bit;
    // End LCD module connections

    char kitu ;

    void main()
    {
    TRISB = 0;
    PORTB = 0xFF;
    TRISB = 0xff;
    adcon1=0x0f; //Configure AN pins as digital
    cmcon=0x07;
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
    Lcd_Out(2,1,"Set : ") ;
    Uart1_Init(9600);
    delay_ms(100);
    while (1) // Endless loop
    {
    if (UART1_Data_Ready()) // If data is received,
    {
    kitu = UART1_Read(); // read the received data,

    lcd_out(2,6,kitu) ;
    }

    }

    }

    giao diện máy tính mình viết bằng C#:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {

    public Form1()
    {
    InitializeComponent();

    serialPort1.Open();
    }
    private void button1_Click(object sender, EventArgs e)
    {
    serialPort1.Write(textBox1.Text);//textbox1 để mình nhập một kí tự vào

    }
    }
    }
  • nhanconan030789
    Đệ tử 3 túi
    • Mar 2009
    • 49

    #2
    UART1_Read() tra ve kieu du lieu char,
    con Lcd_Out(char row, char column, char *text) yeu cau du lieu gui di la kieu string,ban phai convert du lieu

    Comment

    • navy
      Đệ tử 2 túi
      • Jan 2007
      • 34

      #3
      [QUOTE=muatuyet_2012;44162]Mình muốn truyền một kí tự từ máy tính xuống lcd nhưng nó bị lỗi và mình ko biết phải sửa như thế nào cả.
      Mong các bạn giúp đỡ.
      Đây là code của mình.
      Mình viết bằng trình biên dịch Mikroc.

      // LCD module connections
      sbit LCD_RS at RB4_bit;
      sbit LCD_EN at RB5_bit;
      sbit LCD_D4 at RB0_bit;
      sbit LCD_D5 at RB1_bit;
      sbit LCD_D6 at RB2_bit;
      sbit LCD_D7 at RB3_bit;

      sbit LCD_RS_Direction at TRISB4_bit;
      sbit LCD_EN_Direction at TRISB5_bit;
      sbit LCD_D4_Direction at TRISB0_bit;
      sbit LCD_D5_Direction at TRISB1_bit;
      sbit LCD_D6_Direction at TRISB2_bit;
      sbit LCD_D7_Direction at TRISB3_bit;
      // End LCD module connections

      char kitu ;

      void main()
      {
      TRISB = 0;
      PORTB = 0xFF;
      TRISB = 0xff;
      adcon1=0x0f; //Configure AN pins as digital
      cmcon=0x07;
      Lcd_Init(); // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
      Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
      Lcd_Out(2,1,"Set : ") ;
      Uart1_Init(9600);
      delay_ms(100);
      while (1) // Endless loop
      {
      if (UART1_Data_Ready()) // If data is received,
      {
      kitu = UART1_Read(); // read the received data,

      lcd_out(2,6,kitu) ;
      }

      }

      }

      giao diện máy tính mình viết bằng C#:

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;

      namespace WindowsFormsApplication2
      {
      public partial class Form1 : Form
      {

      public Form1()
      {
      InitializeComponent();

      serialPort1.Open();
      }
      private void button1_Click(object sender, EventArgs e)
      {
      serialPort1.Write(textBox1.Text);//textbox1 để mình nhập một kí tự vào

      }
      }
      }[/QUOTE

      Không thấy ai bàn tiếp về MikroC nữa vậy?
      lanhnavy@gmail.com
      Mobile phone: 0974711766
      Automation

      Comment

      • muatuyet_2012
        Nhập môn đệ tử
        • Apr 2010
        • 6

        #4
        Mình đã sửa vấn đề này lâu lắm rồi.thanks mọi người đã giúp đỡ.

        Comment

        Working...