⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 RS232串口通信
💻 C
字号:
/**********************************************************************
  main.c file
  ADuC7027的第二个实验——串口通讯
  作者:Computer-lov
  建立日期:2006-3-22
  修改日期:2006-3-22
  版本:V1.0
  版权所有,盗版必究。
  任何技术问题可到我的博客上留言:    http://computer00.21ic.org
  Copyright(C) Computer-lov 2006-2016
  All rigths reserved
**********************************************************************/

#include <../My_type.h>
#include <ADuC7027.H>
#include "UART.H"
#include "LED.H"



//////////////////////////////////////////////////////////////////////
void sys_clk_init(void)
{
 PLLKEY1=0xAA;
 PLLCON=0x01;   //PLL配置  
 PLLKEY2=0x55;
 POWKEY1=0x01;
 POWCON=0x00;  //CPU时钟配置为41.78MHz
 POWKEY2=0xF4;
// while(!(PLLSTA & 0x01));
}
//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
void main(void)
{
 uint8 temp;
 uint16 count=0; //统计接收字节数

 EN_LED4();
 EN_LED5();
 
 OFF_LED4();
 OFF_LED5();

 sys_clk_init();
 UART_init();
 cls();

 prints("System start....................",1);
 prints("Please use your keyboard to input",1);
 prints("Press Key '4' to turn ON the LED4",1);
 prints("Press Key '5' to turn ON the LED5",1);
 prints("Press Key '$' to turn OFF the LED4",1);
 prints("Press Key '%' to turn OFF the LED5",1);
 prints("Waiting for your input..........",1);

 while(1)
  {
   while(!(COMSTA0 & 0x01));    //等待串口输入
   temp=COMRX;					//读回数据
   cls();						//清屏
   prints("Please use your keyboard to input",1);
   prints("Press Key '4' to turn ON the LED4",1);
   prints("Press Key '5' to turn ON the LED5",1);
   prints("Press Key '$' to turn OFF the LED4",1);
   prints("Press Key '%' to turn OFF the LED5",1);
   prints("",1);
   prints("You pressed key: '",0);
   send_a_byte(temp);				  //显示按键信息
   prints("'",1);            //换行
   prints("Count is: ",0);
   print_uint16(count);
   count++;					//输入次数加一
   prints("",1);
   prints("",1);
   switch(temp)
    {
	 case '4': ON_LED4();prints("LED4 is ON!",1);break;	  //如果收到4,则点亮LED4
	 case '5': ON_LED5();prints("LED5 is ON!",1);break;
	 case '$': OFF_LED4();prints("LED4 is OFF!",1);break;
	 case '%': OFF_LED5();prints("LED5 is OFF!",1);break;

	 default :break;
	} 
  }
}
/////////////////////////////////////////////////////////////////////////////


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -