📄 main.c
字号:
//========================================================================
// The information contained herein is the exclusive property of
// Sunnnorth Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
// (C) COPYRIGHT 2003 SUNNORTH TECHNOLOGY CO.
// ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorized copies.
//========================================================================
//=============================================================================================================
// 工程名称: ex6_UART&LCD&SPR4096
// 功能描述: 《实验仪指导书》综合实验
// UART控制液晶显示
// PC通过UART发送英文字符 ,通过SIO存储到SPR4096中,然后在液晶显示器上显示
// 涉及的库: CMacro1016.lib
// 组成文件: main.c/isr.c/SPLC501User.c
// 4096.asm/DataOSforLCD.asm/SPLC501Driver_IO.asm
// SPCE061A.inc/SPLC501Driver_IO.inc
// SPCE061A.H/SPLC501User.h
// 硬件连接: 实验仪KEYPAD接口的IOA7~IOA0与COL1~COL8分别连接,IOA8与ROW连接
// IOB8~IOB15与LED_SEG接口的a~h连接
// 串口线连接计算机串口,实验仪COMM接口跳线跳接至RS232一端
// CF7->DGND
// SDA->IOB1
// SCK->IOB0
// 维护记录: 2005-10-13 v1.0
//=============================================================================================================
//========================================================================
// 文件名称: main.c
// 功能描述: 主程序
// 维护记录: 2005.10.13 v1.0
//========================================================================
extern void SP_SIOInitial(void);
extern void SP_SIOMassErase(void);
extern unsigned int SP_SIOReadAByte(unsigned long int g_ulAddr);
extern void LCD501_Init(unsigned int InitialData);
void SP_UARTInitial(void);
#define P_Watchdog_Clear (volatile unsigned int *)0x7012
#define C_UARTBaudRate_9600_H 0x05
#define C_UARTBaudRate_9600_L 0x00
#define M_SECTOR 10 //第几个扇区(0~255)
#include "SPCE061A.h"
unsigned long ulStartAddr,ulEndAddr,g_ulAddr;
unsigned int g_uiData,g_uiFlag,g_uiTimeOutCnt,g_uiHalfSecondCnt;
//-------------------------------------------------
// / 0 没有收到数据
// g_uiFlag = - 1 正在接收数据
// \ 2 数据接收完毕
//-------------------------------------------------
//========================================================================
// 语法格式: int main(void)
// 实现功能: 主程序
// 参数: 无
// 返回值: int 无意义
//========================================================================
main()
{
int i,j; //延时变量
int X,Y; //X:横坐标 Y:纵坐标
unsigned char *ucStr1 = "UART Ready";
unsigned char *ucStr2 = "Receiving...";
unsigned char *ucStr3 = "Complete";
unsigned char *ucStr4 = "The Data is";
unsigned char *ucCode;
SP_SIOInitial(); //SIO初始化
SP_UARTInitial(); //UART初始化
LCD501_Init(0x00); //LCD初始化
*P_INT_Ctrl = C_IRQ5_2Hz; //开2Hz中断,用来定时清看门狗和延时
__asm("IRQ ON");
g_uiData = *P_IOB_Buffer; //IOB11:低电平,选择SPR4096的FLASH
g_uiData &= 0xf7ff;
*P_IOB_Data = g_uiData;
ulStartAddr=0x800*(M_SECTOR);
g_ulAddr = ulStartAddr;
SP_SIOMassErase(); //对SPR4096的所有扇区进行擦除
ucCode = ucStr1;
X = 10;
Y = 15;
LCD501_PutString(X,Y,ucCode); //LCD显示ucStr1的内容
g_uiFlag=0;
while(g_uiFlag==0); //等待接收到第一个数据
LCD501_ClrScreen(0); //LCD清屏
ucCode = ucStr2;
X = 10;
Y = 15;
LCD501_PutString(X,Y,ucCode); //LCD显示ucStr2的内容
g_uiTimeOutCnt = 0;
while(g_uiFlag==1) //等待接收完毕
{
g_uiTimeOutCnt++;
if(g_uiTimeOutCnt >= 0xfffe) //判断是否超时?该变量在UART接收中断中会被清零
g_uiFlag = 2;
}
ulEndAddr = g_ulAddr;
LCD501_ClrScreen(0); //LCD清屏
ucCode = ucStr3;
X = 10;
Y = 15;
LCD501_PutString(X,Y,ucCode); //LCD显示ucStr3的内容
for(i=0;i<10;i++) //延时程序,没有特别的作用,只是为了能看清楚现象
for(j=0;j<0x8fff;j++)
*P_Watchdog_Clear = 0x0001;
LCD501_ClrScreen(0); //LCD清屏
LCD501_PutString(5,5,"The Data is:");
g_ulAddr = ulStartAddr;
for(X = 5,Y = 20;g_ulAddr < ulEndAddr;g_ulAddr++)
{
g_uiData=SP_SIOReadAByte(g_ulAddr); //从SPR4096读出一个Byte的数据
LCD501_PutChar(X,Y,g_uiData); //在LCD上显示该数据
X += 8; //下一个数据显示的X位置
if(X > 120) //换行
{
X = 5;
Y += 14; //下一行数据显示的Y位置
}
if(Y > 53) //换屏
{
X = 5;
Y = 20;
g_uiHalfSecondCnt = 0;
while(g_uiHalfSecondCnt < 6); //延时
LCD501_ClrScreen(0); //LCD清屏
}
}
while(1)
*P_Watchdog_Clear = 0x0001;
}
//=============================================================
// 语法格式: void SP_UARTInitial(void);
// 实现功能: UART初始化
// 参数: 无
// 返回值: 无
//=============================================================
void SP_UARTInitial(void)
{
*P_IOB_Dir |= 0x0400; //bit10设为输出口(Tx),bit7设为输入口(Rx)
*P_IOB_Dir &= 0xff7f;
*P_IOB_Attrib |= 0x0480;
*P_IOB_Buffer |= 0x0400;
*P_IOB_Buffer &= 0xfb7f;
*P_UART_Command1 = C_UART_Reset; //UART复位
*P_UART_BaudScalarHigh = C_UARTBaudRate_9600_H; //波特率设为9600
*P_UART_BaudScalarLow = C_UARTBaudRate_9600_L;
*P_UART_Command1 = C_UART_Rx_IRQ_ENB; //UART接收中断使能
*P_UART_Command2 = C_UART_Rx_Pin_ENB; //UART接收管脚使能
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -