|
Tài trợ cho PIC Vietnam |
Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
Ðiều Chỉnh | Xếp Bài |
20-04-2011, 12:55 PM | #1 |
Nhập môn đệ tử
Tham gia ngày: Apr 2010
Bài gửi: 6
: |
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 } } } |
|
|