求大神指点下,我用串口助手发送十六进制数据,为何液晶屏上没显示,谢谢,(发送字符串可以正常显示)
时间:10-02
整理:3721RD
点击:
下面是代码:望大神指点,谢谢了
void USART1_IRQHandler(void) //′??ú1?D??·t??3ìDò
{
u16 i,Res;
#ifdef OS_TICKS_PER_SEC //è?1?ê±?ó?ú??êy?¨ò?á?,?μ?÷òaê1ó?ucosIIá?.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //?óê??D??(?óê?μ?μ?êy?Y±?D?ê?0x0d 0x0a?á?2)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
USART_RX_BUF[i]=USART_ReceiveData(USART1);//(USART1->DR); //?áè??óê?μ?μ?êy?Y
USART_SendData(USART1,USART_RX_BUF[i]);
// write_pos(3,i);
//write_data(USART_ReceiveData(USART1));
//i++
/* if((USART_RX_STA&0x8000)==0)//?óê??′íê3é
{
if(USART_RX_STA&0x4000)//?óê?μ?á?0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//?óê?′í?ó,??D??aê?
else USART_RX_STA|=0x8000; //?óê?íê3éá?
}
else //?1??ê?μ?0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//?óê?êy?Y′í?ó,??D??aê??óê?
}
}
} */
}
#ifdef OS_TICKS_PER_SEC //è?1?ê±?ó?ú??êy?¨ò?á?,?μ?÷òaê1ó?ucosIIá?.
OSIntExit();
#endif
}
#endif
void busy_search(void)//
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOF,&GPIO_InitStructure);
reset_rs;
set_rw;
reset_en;
//Delay(5);
set_en;
// Delay(25);
while(GPIO_ReadInputDataBit(GPIOF,GPIO_Pin_15)==1);
reset_en;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
void write_cmd(uchar cmd)//? cmd?
{
busy_search();
reset_rs;
reset_rw;
reset_en;
GPIO_Write(GPIOF,(0xff00&(cmd<<8)));
delay_us(5);
set_en;
delay_us(5);
reset_en;
}
void write_data(u16 dat)//?, dat?
{
busy_search();
set_rs;
reset_rw;
reset_en;
GPIO_Write(GPIOF,(0xff00&(dat<<8)));
delay_us(5);
set_en;
delay_us(5);
reset_en;
}
void lcd12864_Config()//?
{
write_cmd(0x30);
write_cmd(0x0c);
write_cmd(0x01);
}
void write_pos(uchar x,uchar y)
{
uchar pos;
if(x==0)
{
x=0x80;
}
if(x==1)
{
x=0x90;
}
if(x==2)
{
x=0x88;
}
if(x==3)
{
x=0x98;
}
pos=x+y;
write_cmd(pos);
}
#include "usart.h"
#include "gpio.h"
#include "lcd12864.h"
#include "sys.h"
char str1[]={"μ±?°éè±?:"};
char str2[]={"1¤×÷×′ì?: òì3£"};
char str3[]={"??±êêy?Y: 99 99"};
char *str4;
int a=0x05;
int num,i,j,len,t;
int main(void )
{
gpio_init();//IO?ú3?ê??ˉ
uart_init(9600);//′??ú3?ê??ˉoˉêy
delay_init();//?óê±oˉêy3?ê??ˉ
lcd12864_Config();//òo?§3?ê??ˉoˉêy
write_pos(0,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str1[num]!='\0')
{
write_data(str1[num]);
num++;
}
write_pos(1,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str2[num]!='\0')
{
write_data(str2[num]);
num++;
}
write_pos(2,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str3[num]!='\0')
{
write_data(str3[num]);
num++;
}
while(1)
{
if(USART_RX_STA&0x8000)
{ len=USART_RX_STA&0x3f;
write_pos(3,0);
for(i=0;i<=len;i++)
write_data(USART_RX_BUF[i]);
}
}
}
void USART1_IRQHandler(void) //′??ú1?D??·t??3ìDò
{
u16 i,Res;
#ifdef OS_TICKS_PER_SEC //è?1?ê±?ó?ú??êy?¨ò?á?,?μ?÷òaê1ó?ucosIIá?.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //?óê??D??(?óê?μ?μ?êy?Y±?D?ê?0x0d 0x0a?á?2)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
USART_RX_BUF[i]=USART_ReceiveData(USART1);//(USART1->DR); //?áè??óê?μ?μ?êy?Y
USART_SendData(USART1,USART_RX_BUF[i]);
// write_pos(3,i);
//write_data(USART_ReceiveData(USART1));
//i++
/* if((USART_RX_STA&0x8000)==0)//?óê??′íê3é
{
if(USART_RX_STA&0x4000)//?óê?μ?á?0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//?óê?′í?ó,??D??aê?
else USART_RX_STA|=0x8000; //?óê?íê3éá?
}
else //?1??ê?μ?0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//?óê?êy?Y′í?ó,??D??aê??óê?
}
}
} */
}
#ifdef OS_TICKS_PER_SEC //è?1?ê±?ó?ú??êy?¨ò?á?,?μ?÷òaê1ó?ucosIIá?.
OSIntExit();
#endif
}
#endif
void busy_search(void)//
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOF,&GPIO_InitStructure);
reset_rs;
set_rw;
reset_en;
//Delay(5);
set_en;
// Delay(25);
while(GPIO_ReadInputDataBit(GPIOF,GPIO_Pin_15)==1);
reset_en;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
void write_cmd(uchar cmd)//? cmd?
{
busy_search();
reset_rs;
reset_rw;
reset_en;
GPIO_Write(GPIOF,(0xff00&(cmd<<8)));
delay_us(5);
set_en;
delay_us(5);
reset_en;
}
void write_data(u16 dat)//?, dat?
{
busy_search();
set_rs;
reset_rw;
reset_en;
GPIO_Write(GPIOF,(0xff00&(dat<<8)));
delay_us(5);
set_en;
delay_us(5);
reset_en;
}
void lcd12864_Config()//?
{
write_cmd(0x30);
write_cmd(0x0c);
write_cmd(0x01);
}
void write_pos(uchar x,uchar y)
{
uchar pos;
if(x==0)
{
x=0x80;
}
if(x==1)
{
x=0x90;
}
if(x==2)
{
x=0x88;
}
if(x==3)
{
x=0x98;
}
pos=x+y;
write_cmd(pos);
}
#include "usart.h"
#include "gpio.h"
#include "lcd12864.h"
#include "sys.h"
char str1[]={"μ±?°éè±?:"};
char str2[]={"1¤×÷×′ì?: òì3£"};
char str3[]={"??±êêy?Y: 99 99"};
char *str4;
int a=0x05;
int num,i,j,len,t;
int main(void )
{
gpio_init();//IO?ú3?ê??ˉ
uart_init(9600);//′??ú3?ê??ˉoˉêy
delay_init();//?óê±oˉêy3?ê??ˉ
lcd12864_Config();//òo?§3?ê??ˉoˉêy
write_pos(0,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str1[num]!='\0')
{
write_data(str1[num]);
num++;
}
write_pos(1,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str2[num]!='\0')
{
write_data(str2[num]);
num++;
}
write_pos(2,0);//D′×?±ê£?μúò?DD£?μúò???
num=0;
while(str3[num]!='\0')
{
write_data(str3[num]);
num++;
}
while(1)
{
if(USART_RX_STA&0x8000)
{ len=USART_RX_STA&0x3f;
write_pos(3,0);
for(i=0;i<=len;i++)
write_data(USART_RX_BUF[i]);
}
}
}
麻烦小编将源代码打包,然后上传我才好帮你查看
好多乱码呀,小编你能不能打包上传呀
串口调试助手有没有勾选“以十六进制显示”
如果可以进入调试状态,可以在调试状态看看两个收到的数据是不是一样的。如果不可以进入调试状态尝试着把发送的数据返回串口调试助手,确认两次单片机收的的数据是一致的!