LPC2138外围模块底层驱动程序.docx
《LPC2138外围模块底层驱动程序.docx》由会员分享,可在线阅读,更多相关《LPC2138外围模块底层驱动程序.docx(8页珍藏版)》请在冰豆网上搜索。
LPC2138外围模块底层驱动程序
LPC2138外围模块底层驱动程序(刚写的,待续)
上一篇/下一篇 2008-12-3011:
51:
01
查看(20)/评论(0)/评分(0/0)
/*******************************************************************************************************
*文件名:
main.c
*功 能:
底层驱动模块(触摸屏)
*作 者:
AndyJiang
*日 期:
2008年12月23号
|
| main.c
| byAndyjiang
| 2008.12.123
|
| CS8920softwaregroup
| www.midoriya.co.jp
|
********************************************************************************************************/
#include"config.h"
#define baud_rate 1200
#define ADC0 18
#define ADC1 21
#define UART0 6
#define UART1 7
#define TIMER0 4
#define EXTRN 14
#define TIMER1 5
#define RTC 13
uint32 adresult;
uint32 voltage1;
uint32 voltage2;
//uint8a[100]={0};
uint8send_counter;
uint32 state;
/************************************************************/
/************functionprototypes*****************************/
/************************************************************/
voidEXTRN_Init(void);
voidPort_Init(void);
voidTimer0_Init(void);
voidUART1_Init(void);
voidUART0_Init(void);
voidRTCI_Init(void);
voidUART0_Sendbyte(uint8sendbyte);
voidUART0_Senddata(uint8send_bytes,uint8*buffer);
uint8UART0_Recebyte(void);
voidUART0_Recdata(uint8rece_bytes,uint8*buffer);
voidUART1_Senddata(uint8send_bytes,uint8*buffer);
voidTimer0_Int(void)__irq;
voidADC0_Int (void)__irq ;
voidUart0_Int(void)__irq ;
voidUart1_Int(void)__irq ;
voidEXTRN_Int(void)__irq ;
voidRTC_Int (void)__irq;
/************************************************************/
/***********************serial0driver***********************/
/************************************************************/
voidRTC_Int (void)__irq
{
VICVectAddr=0xFF;
}
voidADC0_Int( )__irq //AD0interruptserviceprogramme
{
VICVectAddr=0xFF;
}
voidADC1_Int( )__irq //AD1interruptserviceprogramme
{
VICVectAddr=0xFF;
}
voidEXTRN_Int( )__irq //EXTRN interruptserviceprogramme
{
IO0SET=0X00;
while((EXTINT&0X01)!
=0X01)
{
EXTINT=0X01;
}
EXTINT=0X01;
VICVectAddr=0xFF;
}
voidTimer0_Int() __irq //Timer0interruptserviceprogramme
{
T0IR=0X01;
VICVectAddr=0xFF;
}
voidUart0_Int( )__irq //UART0 interruptserviceprogramme
{
VICVectAddr=0xFF;
}
voidUart1_Int( ) __irq //UART1 interruptserviceprogramme
{
VICVectAddr=0xFF;
}
void Port_Init(void) //Portinitialize
{
PINSEL0=0X00;
PINSEL1=0X00000001;
// PINSEL2=0X00; //BECAREFORTHISCODE!
!
!
!
!
!
!
IO0DIR=0X00;
IO1DIR=0X00;
IO2DIR=0X00;
IO3DIR=0X00;
IO0SET=0X00;
IO0CLR=0X00;
IO1SET=0X00;
IO1CLR=0X00;
EXTMODE=0X00;
}
void Timer0_Init(void)
{
T0TC=0;
T0PR=0;
T0MCR=0X03;
T0MR0=Fpclk/2;
T0TCR=0X01;
VICIntSelect=0x00000000; /*dispatchasIRQ */
VICVectCntl3=0x20|TIMER0; /*Timer0 asIRQslot1 */
VICVectAddr3=(uint32)Timer0_Int; /*gettimer0interservice */
VICIntEnable=1<
}
voidUART0_Init(void)
{
PINSEL0=PINSEL0&(~0x0F)|0x05; /*EnableRxD0andTxD0 */
U0LCR=0x83; /*8bits,noParity,1Stopbit */
U0DLL=625%256; /*1200BaudRate@12MHzVPBClock*/
U0DLM= 625/256;
U0LCR=0x03; /*LOCK*/
U0IER=0X07;
//U0LCR=0X81; /*INTENABLE*/
VICVectCntl0=0x20|UART0; /*UART0asIRQslot0*/
VICVectAddr0=(uint32)Uart0_Int; /*getUART0interservice*/
VICIntEnable=1< }
voidUART1_Init(void)
{
PINSEL0=PINSEL0&(~(0x0F<<16))|(0x05<<16); /*EnableRxD1andTxD1 */
U1LCR=0x83; /*8bits,noParity,1Stopbit */
U1DLL=65535%256; /*1200BaudRate@12MHzVPBClock*/
U1DLM=65535/256;
U1LCR=0x03;
U1IER=0X03;
VICVectCntl0=0x20|UART1; /*UART0asIRQslot0*/
VICVectAddr2=(uint32)Uart1_Int; /*getUART0interservice*/
VICIntEnable=1< }
uint16ADC0_Init(void)
{
uint16adresult;
VICIntSelect=0x00000000; //dispatchasIRQ
VICVectCntl0=0x20|ADC0; //AD0asIRQslot0
VICVectAddr0=(uint32)ADC0_Int; //getadinterservice
VICIntEnable=1< return (adresult);
}
uint16ADC1_Init(void)
{
uint16adresult;
VICIntSelect=0x00000000; //dispatchasIRQ
VICVectCntl0=0x20|ADC1; //AD0asIRQslot0
VICVectAddr0=(uint32)ADC1_Int; //getadinterservice
VICIntEnable=1< return (adresult);
}
void EXTRN_Init(void)
{
VICIntSelect=0x00000000; //dispatchasIRQ
PINSEL0=0X00000001;
VICVectCntl0=0x20|EXTRN; //EXT0asIRQslot0
VICVectAddr0=(uint32)EXTRN_Int; //getadinterservice
VICIntEnable=1< }
voidUART0_Sendbyte(uint8sendbyte)
{
U0THR=sendbyte;
while(U0LSR&0X40==0);
}
void RTC_Init(void)
{
PREINT=Fpclk/32768-1;
PREFRAC=Fpclk-(Fpclk/32768)*32768;
CIIR=0X01;
VICIntSelect=0x00000000; /*dispatchasIRQ */
VICVectCntl3=0x20|RTC; /*Timer0 asIRQslot1 */
VICVectAddr3=(uint32)RTC_Int; /*gettimer0interservice */
VICIntEnable=1<