Main.c
资源名称:ISP.rar [点击查看]
上传用户:cchhkk2004
上传日期:2022-05-10
资源大小:78k
文件大小:5k
源码类别:
VxWorks
开发平台:
Others
- //--------------------------------------------------------------------------------
- #include <stdio.h> /* prototype declarations for I/O functions */
- #include <LPC21xx.H> /* LPC21xx definitions */
- #include "Main.h"
- //--------------------------------------------------------------------------------
- void UART0_Init (void)
- {
- UINT16 Fdiv;
- PINSEL0 = 0;
- PINSEL0 &= ~(3 < 0);
- PINSEL0 &= ~(3 < 2);
- PINSEL0 |= (0x01 < 0);
- PINSEL0 |= (0x01 < 2);
- U0LCR = 0x83; // DLAB = 1,可设置波特率
- Fdiv = (Fpclk / 16)/ UART_BPS; // 设置波特率
- U0DLM = Fdiv / 256;
- U0DLL = Fdiv % 256;
- U0LCR = 0x03;
- }
- //--------------------------------------------------------------------------------
- void UART1_Init (void)
- {
- #if 0
- UINT16 Fdiv;
- PINSEL0 = 0;
- PINSEL0 &= ~(3 < 16);
- PINSEL0 &= ~(3 < 18);
- PINSEL0 |= (0x01 < 16);
- PINSEL0 |= (0x01 < 18);
- U1LCR = 0x83; // DLAB = 1,可设置波特率
- Fdiv = (Fpclk / 16)/ UART_BPS; // 设置波特率
- U1DLM = Fdiv / 256;
- U1DLL = Fdiv % 256;
- U1LCR = 0x03;
- #endif
- UINT16 Fdiv;
- PINSEL0 = 0x00050000;
- U1LCR = 0x83; // DLAB = 1,可设置波特率
- Fdiv = (Fpclk / 16)/ UART_BPS; // 设置波特率
- U1DLM = Fdiv / 256;
- U1DLL = Fdiv % 256;
- U1LCR = 0x03;
- }
- //--------------------------------------------------------------------------------
- void PLL_Init(void)
- {
- /* 设置系统各部分时钟 */
- PLLCON = 1;
- #if ((Fcclk / 4) / Fpclk) == 1
- VPBDIV = 0;
- #endif
- #if ((Fcclk / 4) / Fpclk) == 2
- VPBDIV = 2;
- #endif
- #if ((Fcclk / 4) / Fpclk) == 4
- VPBDIV = 1;
- #endif
- #if (Fcco / Fcclk) == 2
- PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
- #endif
- #if (Fcco / Fcclk) == 4
- PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
- #endif
- #if (Fcco / Fcclk) == 8
- PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
- #endif
- #if (Fcco / Fcclk) == 16
- PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
- #endif
- PLLFEED = 0xaa;
- PLLFEED = 0x55;
- while((PLLSTAT & (1 << 10)) == 0);
- PLLCON = 3;
- PLLFEED = 0xaa;
- PLLFEED = 0x55;
- }
- //--------------------------------------------------------------------------------
- #define GPIO10 10
- #define GPIO11 11
- #define GPIO12 12
- #define GPIO13 13
- //--------------------------------------------------------------------------------
- int main (void)
- {
- //MAM_init();
- PLL_Init();
- #ifdef USE_UART0_MSG
- UART0_Init();
- #else
- UART1_Init();
- #endif
- RTCInit();
- GPIO_init(GPIO11);
- GPIO_inout(GPIO11,OUTPUT);
- printf (" ---- Program start ---- n");
- while(TRUE)
- {
- }
- }
- //--------------------------------------------------------------------------------
- void GPIO_init(UINT8 GPIO_num)
- {
- if(GPIO_num < 16)
- PINSEL0 &= ~(0x03 << (GPIO_num * 2));
- else
- PINSEL1 &= ~(0x03 << ((GPIO_num-16) * 2));
- }
- void GPIO_inout(UINT8 GPIO_num,UINT8 in_out)
- {
- if(in_out)
- IODIR0 |= (0x01 << GPIO_num);//output
- else
- IODIR0 &= ~(0x01 << GPIO_num); //input
- }
- //--------------------------------------------------------------------------------
- UINT8 GPIO_READ(UINT8 GPIO_num)
- {
- if(IOPIN0 & (1 << GPIO_num))
- return 1;
- else
- return 0;
- }
- //--------------------------------------------------------------------------------
- void MAM_init(void)
- {
- MAMCR = 0x02;
- MAMTIM = 0x03;
- }
- //--------------------------------------------------------------------------------
- void RTCInit(void)
- {
- YEAR = 2009; // 初化年
- MONTH = 04; // 初化月
- DOM = 10; // 初化日
- HOUR = 12;
- MIN = 43;
- SEC = 00;
- CIIR = 0x01; // 设置秒值的增量产生一次中断
- ILR = 0x03;
- CCR = 0x11; // 使用独立振荡器,启动RTC
- VICVectCntl1 = 0x20 |13;
- VICVectAddr1 = (UINT32)IRQ_RTC;
- VICIntEnable |= (1 << 13);
- }
- //--------------------------------------------------------------------------------
- void GPIO_SET(UINT8 GPIO_num,UINT8 High_Low)
- {
- if(High_Low)
- IOSET0 |= (0x01 << GPIO_num);
- else
- IOCLR0 |= (0x01 << GPIO_num);
- }
- //--------------------------------------------------------------------------------
- void __irq IRQ_RTC (void)
- {
- //static UINT8 i = 0;
- //printf("-- RTC VIC interrupt -- %dn",i--);
- printf("RTC -- %4u : %02u : %02u : %02u : %02u : %02un",YEAR,MONTH,DOM,HOUR,MIN,SEC);
- if(GPIO_READ(GPIO11))
- GPIO_SET(GPIO11,LOW);
- else
- GPIO_SET(GPIO11,HIGH);
- ILR = 0x01; /* 清除中断标志 */
- VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
- }
- //--------------------------------------------------------------------------------