📄 main.cpp
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include "Pin_LPC2138.h"
#include "Uart_LPC2138.h"
#include "Timer_LPC2138.h"
#include "PinDevice_LPC2138.h"
Pin_LPC2138 PIN008,PIN009;//串口用于Txd Rxd ,适用于串口1
Pin_LPC2138 PIN019,PIN021;//串口用于Txd Rxd ,适用于串口0
Uart_LPC2138 UartDevice0; /*串口0*/
Uart_LPC2138 UartDevice1; /*串口1*/
Timer_Lpc2138 TimerDevice0;
Pin_LPC2138 PIN006;
// char writedata[4]={0xAA,0x55,0xff,0x11};
char writedata[14] = "abcdefghijklm";
class PinSubDevice:public PinDevice_Virtual_Device
{
public:
void OnTimer()
{
if (PinDevice->PinValue() == 0)
PinDevice->Set();
else
PinDevice->Clear();
}
};
PinSubDevice PinLed;
/************初时化引脚************/
void Ini_Pin()
{
/***********串口1的引脚 *************/
PIN008.SetPinTag("P008");
PIN008.Function=1;
PIN008.Ini();
PIN009.SetPinTag("P009");
PIN009.Function=1;
PIN009.Ini();
/***********串口0的引脚 *************/
PIN019.SetPinTag("P000");
PIN019.Function=1;
PIN019.Ini();
PIN021.SetPinTag("P001");
PIN021.Function=1;
PIN021.Ini();
////////////////////////////////////////
PIN006.SetPinTag("P020");
PIN006.Function=0;
PIN006.Dirction = 1;
PIN006.Ini();
PIN006.Set();
};
/************串口中断处理的相应函数************/
void __irq IRQ_Uart1()
{
UartDevice1.HardInt(Null);
VICVectAddr = 0x00;
}
void __irq IRQ_Uart0()
{
UartDevice0.HardInt(Null);
VICVectAddr = 0x00;
}
/************定时器相应函数************/
void __irq IRQ_Timer()
{
*( TimerDevice0.BasePointer+Timer_IR_Offset)=0x01;
TimerDevice0.HardInt();
VICVectAddr = 0x00;
};
char buffer[100];
int main (void)
{
Ini_Pin();
PinLed.PinDevice = &PIN006;
//初始化串口0*/
UartDevice0.SubDeviceName=Uart0;
UartDevice0.WorkFreq=Fpclk;
UartDevice0.BandBps=19200;
UartDevice0.Ini(); //奇偶校验,数据位,停止位在哪里设置?答:已经是标准模式了,设置好的了
//初始化串口1*/
UartDevice1.SubDeviceName=Uart1;
UartDevice1.WorkFreq=Fpclk;
UartDevice1.BandBps=19200;
UartDevice1.Ini(); //奇偶校验,数据位,停止位在哪里设置?答:已经是标准模式了,设置好的了
/*初始化定时器*/
TimerDevice0.SubDeviceName=Timer0;
TimerDevice0.WorkFreq=Fpclk;
TimerDevice0.OutFreq=2000;
TimerDevice0.TimerRegister(&PinLed);
TimerDevice0.Ini();
VICIntSelect = 0x00; // 所有中断通道设置为IRQ中断
////////////////串口1中断设置
VICVectCntl2 = 0x20 |(UartIrqBase+UartDevice1.SubDeviceName);
VICVectAddr2 = (uint32)IRQ_Uart1;
VICIntEnable=1<<(UartIrqBase+ UartDevice1.SubDeviceName);
////////////////串口0中断设置
// VICIntSelect = 0x00; // 所有中断通道设置为IRQ中断
VICVectCntl1 = 0x20 |(UartIrqBase+UartDevice0.SubDeviceName);
VICVectAddr1 = (uint32)IRQ_Uart0;
VICIntEnable=1<<(UartIrqBase+ UartDevice0.SubDeviceName);
/*定时器中断设置*/
VICIntSelect = 0x00;
VICVectCntl3 = 0x20 |(TimerIrqBase+TimerDevice0.SubDeviceName);
VICVectAddr3 = (uint32)IRQ_Timer;
VICIntEnable=1<<(TimerIrqBase+ TimerDevice0.SubDeviceName);
IRQEnable();
while(1)
{
UartDevice0. WriteData(writedata,13);
DelayNS(100000);
UartDevice1. WriteData(writedata,13);
DelayNS(100000);
};
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -