1、LPC2138外围模块底层驱动程序LPC2138外围模块底层驱动程序(刚写的,待续)上一篇 / 下一篇 2008-12-30 11:51:01 查看( 20 ) / 评论( 0 ) / 评分( 0 / 0 ) /* 文件名:main.c* 功 能:底层驱动模块(触摸屏)* 作 者:Andy Jiang* 日 期:2008年12月23号| main.c| by Andy jiang| 2008.12.123| | CS8920 software group| www.midoriya.co.jp| */#include config.h#define baud_rate 1200#define
2、ADC0 18#define ADC1 21#define UART0 6#define UART1 7#define TIMER0 4#define EXTRN 14#define TIMER1 5#define RTC 13uint32 adresult;uint32 voltage1;uint32 voltage2;/uint8 a100=0;uint8 send_counter;uint32 state;/*/*function prototypes*/*/void EXTRN_Init(void);void Port_Init( void );void Timer0_Init( vo
3、id );void UART1_Init( void );void UART0_Init( void );void RTCI_Init( void );void UART0_Sendbyte( uint8 sendbyte);void UART0_Senddata( uint8 send_bytes, uint8 *buffer );uint8 UART0_Recebyte( void ); void UART0_Recdata( uint8 rece_bytes, uint8 *buffer );void UART1_Senddata(uint8 send_bytes, uint8 *buf
4、fer );void Timer0_Int( void ) _irq ; void ADC0_Int ( void ) _irq;void Uart0_Int ( void ) _irq;void Uart1_Int ( void ) _irq;void EXTRN_Int ( void ) _irq;void RTC_Int ( void ) _irq ; /*/*serial0 driver*/*/ void RTC_Int ( void ) _irq VICVectAddr=0xFF;void ADC0_Int( ) _irq /AD0 i nterrupt service progra
5、mme VICVectAddr=0xFF; void ADC1_Int( ) _irq /AD1 interrupt service programme VICVectAddr=0xFF; void EXTRN_Int( ) _irq /EXTRN interrupt service programme IO0SET=0X00; while(EXTINT&0X01)!=0X01) EXTINT=0X01; EXTINT=0X01; VICVectAddr=0xFF; void Timer0_Int( ) _irq /Timer0 interrupt service programme T0IR
6、=0X01; VICVectAddr=0xFF; void Uart0_Int( ) _irq /UART0 interrupt service programme VICVectAddr = 0xFF; void Uart1_Int( )_irq /UART1 interrupt service programme VICVectAddr = 0xFF; void Port_Init( void ) / Port initialize PINSEL0=0X00; PINSEL1=0X00000001; / PINSEL2=0X00; /BE CARE FOR THIS CODE!! IO0D
7、IR= 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; /*dispatch as IRQ */ VICVectCntl3= 0x20|TIMER0; /*Timer0 as IRQ slo
8、t1 */ VICVectAddr3= (uint32)Timer0_Int; /*get timer0 inter service */ VICIntEnable= 1TIMER0; /*timer0 Enable */ void UART0_Init( void ) PINSEL0= PINSEL0&(0x0F)|0x05; /* Enable RxD0 and TxD0 */ U0LCR= 0x83; /* 8 bits, no Parity, 1 Stop bit */ U0DLL= 625%256; /* 1200 Baud Rate 12MHz VPB Clock */ U0DLM
9、= 625/256; U0LCR= 0x03; /*LOCK*/ U0IER= 0X07; / U0LCR=0X81; /*INT ENABLE*/ VICVectCntl0= 0x20|UART0; /*UART0 as IRQ slot0*/ VICVectAddr0= (uint32)Uart0_Int; /*get UART0 inter service*/ VICIntEnable= 1UART0; void UART1_Init( void ) PINSEL0= PINSEL0&(0x0F16)|(0x0516); /* Enable RxD1 and TxD1 */ U1LCR=
10、 0x83; /* 8 bits, no Parity, 1 Stop bit */ U1DLL= 65535%256; /* 1200 Baud Rate 12MHz VPB Clock */ U1DLM= 65535/256; U1LCR= 0x03; U1IER= 0X03; VICVectCntl0= 0x20|UART1; /*UART0 as IRQ slot0*/ VICVectAddr2= (uint32)Uart1_Int; /*get UART0 inter service*/ VICIntEnable= 1UART1; uint16 ADC0_Init( void) ui
11、nt16 adresult; VICIntSelect=0x00000000; /dispatch as IRQ VICVectCntl0=0x20|ADC0; /AD0 as IRQ slot0 VICVectAddr0=(uint32)ADC0_Int; /get ad inter service VICIntEnable=1ADC0; return (adresult); uint16 ADC1_Init( void) uint16 adresult; VICIntSelect=0x00000000; /dispatch as IRQ VICVectCntl0=0x20|ADC1; /A
12、D0 as IRQ slot0 VICVectAddr0=(uint32)ADC1_Int; /get ad inter service VICIntEnable=1ADC1; return (adresult); void EXTRN_Init( void) VICIntSelect=0x00000000; /dispatch as IRQ PINSEL0=0X00000001; VICVectCntl0=0x20|EXTRN; /EXT0 as IRQ slot0 VICVectAddr0=(uint32)EXTRN_Int; /get ad inter service VICIntEna
13、ble=1EXTRN; void UART0_Sendbyte(uint8 sendbyte) U0THR= sendbyte; while( U0LSR&0X40= 0); void RTC_Init( void) PREINT=Fpclk/32768-1; PREFRAC=Fpclk-(Fpclk/32768)*32768; CIIR=0X01; VICIntSelect= 0x00000000; /*dispatch as IRQ */ VICVectCntl3= 0x20|RTC; /*Timer0 as IRQ slot1 */ VICVectAddr3= (uint32)RTC_I
14、nt; /*get timer0 inter service */ VICIntEnable= 1RTC; /*timer0 Enable */ void UART0_Senddata(uint8 send_bytes, uint8 *buffer) uint8 i ; for(i=0; isend_bytes; i+) U0THR=*buffer; buffer+; while( U0LSR&0x40= 0); uint8 UART0_Recebyte( void ) uint8 Recebyte; while(!(U0LSR&0X01); Recebyte=U0RBR; return (R
15、ecebyte); void UART0_Recdata( uint8 rece_bytes,uint8 *buffer) uint8 i ; for(i=0; irece_bytes; i+) while(!(U0LSR&0X01); *buffer=U0RBR; buffer+; /*/*serial1 driver*/*/ void UART1_Senddata(uint8 send_bytes, uint8 *buffer) uint8 i ; for(i=0;isend_bytes;i+) U1THR=*buffer; buffer+; while( U1LSR&0x40=0); v
16、oid UART1_Recdata( uint8 rece_bytes,uint8 *buffer) uint8 i ; for(i=0;irece_bytes;i+) while(!(U1LSR&0X01); *buffer=U1RBR; buffer+; void delayms(uint8 time) uint16 i;uint16 j;uint8 k;for(i=0;i=time;i+) for(j=0;j=10000;j+) for(k=0;k=10000 ;k+) ; void touchgetx( void ) uint8 adtime; IOSET=IOSET|0X02; IO
17、0CLR=IO0CLR|0X02; delayms(10); for( adtime=0;adtime=20;adtime+) ; /*/*中断服务程序*/*/*/*主程序*/*/ int main ( ) uint8 volt_high,volt_low,volt_midd; / IRQEnable( ); /IRQ enable Port_Init( ); Timer0_Init( ); UART0_Init( ); UART1_Init( ); ADC0_Init( ); ADC1_Init( ); / while(1) ; / UART0_Init( ); / while(1) / / UART0_Sendbyte(0x30); / while(1); / /*/ /*AD SUB PROG*/ /*/ / PINSEL1=PINSEL1&(0X0326)|(0X0126); /pin mapped as ad in / AD0CR=(12) | /channel select / (0XFF8) | /convert clock frequency
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1