[mw_shl_code=c,true]#include "usart.h"
#include "gpio.h"
#include "lcd12864.h"
#include "sys.h"
char str1[]={"?±?°?è±?:"};
char str2[]={"?¤×÷×???: ?ì??"};
char str3[]={"??±ê????: 99 99"};
char *str4;
int a=0x05;
int num,i,j,len,t;
int main(void )
{
gpio_init();//IO????????
uart_init(9600);//?®????????????
delay_init();//???±??????????
lcd12864_Config();//???§??????????
write_pos(0,0);//??×?±ê????????????????
num=0;
while(str1[num]!='\0')
{
write_data(str1[num]);
num++;
}
write_pos(1,0);//??×?±ê????????????????
num=0;
while(str2[num]!='\0')
{
write_data(str2[num]);
num++;
}
write_pos(2,0);//??×?±ê????????????????
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;)
void USART1_IRQHandler(void) //?®??1????·??????ò
{
u16 i,Res;
#ifdef OS_TICKS_PER_SEC //?????±?????????¨????,???÷??????ucosII??.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //????????(????????????±?????0x0d 0x0a?á??)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
USART_RX_BUF=USART_ReceiveData(USART1);//(USART1->DR); //????????????????
USART_SendData(USART1,USART_RX_BUF);
i++;
// write_pos(3,i);
//write_data(USART_ReceiveData(USART1));
//i++
/* if((USART_RX_STA&0x8000)==0)//???????ê??
{
if(USART_RX_STA&0x4000)//????????0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//?????í?ó,????????
else USART_RX_STA|=0x8000; //?????ê????
}
else //????????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;//?????????í?ó,????????????
}
}
} */
}
#ifdef OS_TICKS_PER_SEC //?????±?????????¨????,???÷??????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);
}利用串口助手输入字符串可以正常显示,但是如果是十六进制的数据就不行了,跪求大神[/mw_shl_code]
|