📄 main1.c
字号:
/************************************************************************************
*
* 文件名称: Uart.c
* 文件标识: none
* 适用器件: C8051F020
*
* 摘 要: 本文件是串口0、1测试程序,将跳线器JP7、JP11短接。使用外部22.1184MHz晶振。
* 功能:Uart驱动程序,包括初始化、波特率设置,单字节发送接收、字符串发送接受等。
* 程序运行时向PC机发送"WWW.MLARM.COM";接收到PC机的数据后,再将该数据发送
* 回PC机。按开发板上键盘,将该键值发送到PC机.串口调试最好应用支持中文格式
* 的串口调试助手,否则不能正常显示。
*
*************************************************************************************/
/************************************************************************************/
// 引用外部头文件
#include "c8051f020.h"
#include "uart.h"
#include "key.h"
#include "delay.h"
#include "lcd.h"
/************************************************************************************/
unsigned char code ASCII[16] ={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
0x41,0x42,0x43,0x44,0x45,0x46};
/************************************************************************************
// 系统初始化功能子程序
*************************************************************************************/
/***********************************************************************************
* 函数名称:SYSCLK_Init;
*
* 函数功能描述:系统时钟初始化,使用外部22.1184MHz晶振作为时钟源;
*
* 输入参数:none;
*
* 返回数据:none;
*
* 注意: none;
************************************************************************************/
void SYSCLK_Init (void)
{
int i; // 延时计数器
OSCXCN = 0x67; // 使用外部22.1184MHz晶振
for(i=0; i<256; i++); // 等待1ms
while(!(OSCXCN & 0x80)); // 等待外部振荡器稳定
OSCICN = 0x88; // 切换到外部晶振
}
/***********************************************************************************
* 函数名称:PORT_Init;
*
* 函数功能描述:配置端口初始化,配置交叉开关和端口;
*
* 输入参数:none;
*
* 返回数据:none;
*
* 注意: none;
************************************************************************************/
void PORT_Init (void)
{
XBR0 = 0x8f; //设置XBR0
XBR1 = 0x1e; //设置XBR1
XBR2 = 0x44; //打开交叉开关和弱上拉
P0MDOUT = 0x34; //设置P0口输出
P1MDOUT = 0xfc; //设置P1口输出
P1MDIN = 0xff; //设置P1口输入信号类型
P2MDOUT = 0xf0; //设置P2口输出
P3MDOUT = 0xff; //设置P3口全部推挽输出
P74OUT = 0xf7; //设置P4-P7口输出
P4 = 0xe0; //P4口置0,禁铃
EMI0CF=0x2d; //外部存储器接口配置
EMI0TC=0X9e; //外部存储器时序控制
}
/************************************************************************************
// 主循环程序
*************************************************************************************/
void main(void)
{
unsigned char data temp0,temp1;
unsigned char keytest;
unsigned char data aa[10]={5,4,3,2,1,5,6,7,8,9};
unsigned char i;
WDTCN=0xDE; //禁止看门狗定时器
WDTCN=0xAD;
SYSCLK_Init();
PORT_Init();
lcd_init();
dis_clr();
dis_start0();
Key_Init();
Uart0_Init(BaudRate_115200);
Uart1_Init(BaudRate_115200);
for(i=0;i<4;i++)
{ Uart0_SendByte(aa[i]);}
//Uart0_SendString("西安铭朗电子科技有限责任公司 www.mlarm.com\r\n");
//Uart1_SendString("Compiler Tools: Keil C, V7.02\r\n");
//Uart1_SendString("西安铭朗电子科技有限责任公司 www.mlarm.com\r\n");
while(1)
{
temp0=Uart0_ReceiveData();
temp1=Uart1_ReceiveData();
if (temp0!=0xff)
{
Uart0_SendByte(temp0);
}
if (temp1!=0xff)
{
Uart1_SendByte(temp1);
}
keytest=GetKey();
if (keytest!=0xff)
{
Uart0_SendByte(ASCII[keytest]);
Uart1_SendByte(ASCII[keytest]);
}
}
//------------------------------------Uart0------------------------------------
/*
Uart0_Init(BaudRate_9600);
Uart0_Enable(1);
while(1)
{
Uart0_SendString("Compiler Tools: Keil C, V7.02\r\n");
Uart0_SendString("西安铭朗电子科技有限责任公司 www.mlarm.com\r\n");
temp=Uart0_ReceiveData();
Uart0_SendByte(temp);
}
*/
//------------------------------------Uart1------------------------------------
/*
Uart1_Init(BaudRate_9600);
Uart1_Enable(1);
while(1)
{
Uart1_SendString("Compiler Tools: Keil C, V7.02\r\n");
Uart1_SendString("西安铭朗电子科技有限责任公司www.mlarm.com\r\n");
temp=Uart1_ReceiveData();
Uart1_SendByte(temp);
}
*/
//-----------------------------------------------------------------------------
}
/***********************************************************************************/
// 文件结束
/***********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -