本帖最后由 新塘初级用户 于 2020-7-24 09:36 编辑
#include "n76e003.h"
#include "system.h"
#include "tm1650.h"
#include "stdio.h"
#include "BC26.h"
#include "string.h"
#define CHARTAST 1
#define NUMTAST 2
#define MENUTAST 3
#define BUFLEN 32 //字符串长度
typedef struct _UART_BUF
{
char buf [BUFLEN+1];
unsigned int index ;
}UART_BUF;
bit HaveTast=0;
unsigned char Uart0Cmd;
int SET_BIT4=0X10;
int CLR_BIT4=0XEF;
UART_BUF buf_uart2; //给字符串数组分配空间
void Uart0_Init(void);
void Uart0_Process(void);
void Uart0_SendChar(unsigned char Udat);
void Uart0_SendString(unsigned char *PBuf);
void Clear_Buffer(void) //数组清空
{
Delay_ms(30);
buf_uart2.index=0;
memset(buf_uart2.buf,1,BUFLEN);
}
void nbiot_receive_process_event(unsigned char ch ) //将字符依次存入数组
{
if(buf_uart2.index >= BUFLEN)
{
buf_uart2.index = 0 ;
}
else{
buf_uart2.buf[buf_uart2.index] = ch;
buf_uart2.index++;
}
}
void USART2_IRQHandler() interrupt 4
{
char temp;
temp=SBUF;
nbiot_receive_process_event(temp); 将SUBF依次存入数组
RI=0; //串口中断标志位 置0
}
void main(void)
{
System_Init();
TM1650_Init();
ToDisplay__();
Uart0_Init();
MODIFY_HIRC_166(); //调整波特率
while(1)
{
Uart0_SendString(buf_uart2.buf); //打印字符串内容
Delay_ms(1000);
}
}
void Uart0_Init(void)
{
SCON=0x50; //模式一,定时器,八位自动重装
ClrBits(TMOD,T1_GATE|T1_CT|T1_M0);
SetBits(TMOD,T1_M1);
SetBits(PCON,SMOD);
SetBits(CKCON,T1M);
ClrBits(T3CON,BRCK);
TH1=256 - (1000000/115200+1); //波特率115200 16.6MHz
TR1=1;
ES=1;
EA=1;
P0_Quasi_Mode(PIN_6|PIN_7);
}
void Uart0_SendChar(unsigned char Udat) //串口发送单个字符
{
SBUF=Udat;
while(!TI);
TI=0;
}
void Uart0_SendString(unsigned char *PBuf) //串口发送字符串
{
while(*PBuf!='\0')
{
Uart0_SendChar(*PBuf);
PBuf++;
}
}
void MODIFY_HIRC_166(void) //调整时钟
{
unsigned char hircmap0,hircmap1;
unsigned int trimvalue16bit;
if ((PCON&SET_BIT4)==SET_BIT4)
{
hircmap0 = RCTRIM0;
hircmap1 = RCTRIM1;
trimvalue16bit = ((hircmap0<<1)+(hircmap1&0x01));
trimvalue16bit = trimvalue16bit - 15;
hircmap1 = trimvalue16bit&0x01;
hircmap0 = trimvalue16bit>>1;
TA=0XAA;
TA=0X55;
RCTRIM0 = hircmap0;
TA=0XAA;
TA=0X55;
RCTRIM1 = hircmap1;
PCON &= CLR_BIT4;
}
}
[img][/img]
|
process和isr这两个函数没有调用,不用管它
不知为何,复制过来的代码注释是乱码,不好意思