繁体   English   中英

UART pic18至pic18

[英]UART pic18 to pic18

无法发送字符“ 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。 谢谢。

我曾经遇到过这个问题,事实是角色不是未签名的字符。 因此,请尝试投放。

...
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);
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM