PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Giao tiếp USB, CAN, I2C, SPI, USART... (http://www.picvietnam.com/forum/forumdisplay.php?f=45)
-   -   Giúp uart và lcd với mikroc (http://www.picvietnam.com/forum/showthread.php?t=8929)

muatuyet_2012 20-04-2011 12:55 PM

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 26-07-2011 12:31 AM

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

navy 08-01-2012 11:50 PM

[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?

muatuyet_2012 13-07-2012 11:20 AM

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


Múi giờ GMT. Hiện tại là 08:14 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam