gpt4 book ai didi

c - UART pic18 到 pic18

转载 作者:太空宇宙 更新时间:2023-11-04 02:49:23 25 4
gpt4 key购买 nike

无法发送字符“C”并显示在接收方图片上。 LCD 打印一些特殊字符,没有 'C'... ;(

发射器:

char uart_rd;
int uart_rdi;

sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;


void main() {
ANSELA = 0; // Configure AN pins as digital
ANSELB = 0;
ANSELC = 0;

Lcd_Init();

UART2_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize



while (1) {

UART2_Write('C');
}
}

接收者:

char uart_rd;
int uart_rdi;

sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;


void main() {
ANSELA = 0; // Configure AN pins as digital
ANSELB = 0;
ANSELC = 0;

Lcd_Init();

UART2_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize


while (1) {
if (UART2_Data_Ready()) { // If data is received,
uart_rdi = UART2_Read(); // read the received data,
uart_rd = uart_rdi;
LCD_Out(1,1, uart_rd);

}
}
}

放两张图 18F26K22,串口新手。。。没有设备不知道怎么测试,我的代码好吗?我不使用 Proteus,在金属上工作。谢谢。

最佳答案

我曾经遇到过这个问题,事实是这个字符不是一个unsigned char。所以尝试转换它。

...
while (1) {
if (UART2_Data_Ready()) { // If data is received,
uart_rdi = UART2_Read(); // read the received data,
uart_rd = uart_rdi;
LCD_Out(1,1, (unsigned char) uart_rd);
...

关于c - UART pic18 到 pic18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23770845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com