ARM复习
4.1基本IO实验(LED控制)
控制实验平台的发光二极管LED1,LED2,LED3,LED4,使它们有规律的点亮和熄灭,具体顺序如下:LED1 亮->LED2 亮->LED3 亮->LED4 亮->LED1 灭->LED2 灭->LED3 灭->LED4 灭->全亮->全灭,如此反复。
/******************************************************************************* name: * func:
led_on
turn on the leds one by one
******************************************************************************/ void led_on(void) { }
/******************************************************************************* name: * func:
led_off
turn off the leds one by one
int i,nOut; nOut = 0xF0;
rGPFDAT = nOut & 0x70; for(i=0;i<100000;i++); rGPFDAT=nOut & 0x30; for(i=0;i<100000;i++); rGPFDAT=nOut & 0x10; for(i=0;i<100000;i++); rGPFDAT=nOut & 0x00; for(i=0;i<100000;i++);
******************************************************************************/ void led_off(void) {
int i,nOut; nOut=0;
1
}
rGPFDAT = 0;
for(i=0;i<100000;i++); rGPFDAT = nOut | 0x80; for(i=0;i<100000;i++); rGPFDAT |= nOut | 0x40; for(i=0;i<100000;i++); rGPFDAT |= nOut | 0x20; for(i=0;i<100000;i++); rGPFDAT |= nOut | 0x10; for(i=0;i<100000;i++);
/******************************************************************************* name: * func:
led_on_off
turn on the 4 leds and then turn off the 4 leds
******************************************************************************/void led_on_off(void) { }
/******************************************************************************* name: * func:
led_test
i/o control test(led)
int i; rGPFDAT=0;
for(i=0;i<100000;i++); rGPFDAT=0xF0;
for(i=0;i<100000;i++);
******************************************************************************/void led_test(void) {
rGPFCON=0x5500;
2
// PORTF7/6/5/4 OUTPUT
rGPFUP=0;
// PULL-UP ENABLE
// beep configuration
//rGPBCON = rGPBCON & 0xFFFFFC|1;
uart_printf(\//rGPBDAT &= 0xFFFFFE; led_on(); led_off();
led_on_off(); //rGPBDAT |= 1; delay(1000); rGPFCON = 0x55aa;
//GPF1,GPF0=10 :EINT1,EINT0,(2410lib.c)
uart_printf(\}
中 断 实 验
通过UART0 选择中断触发方式,使能外部中断Eint0、Eint11; 1. 中断初始化程序
/*********************************************************** * name: int_init
* func: Interrupt initialize * comment:
* EINT0 --- SB202 EINT11 --- SB203
************************************************************/ void int_init(void) //中断初始函数 {
rSRCPND = rSRCPND; // clear all interrupt rINTPND = rINTPND; // clear all interrupt rGPFCON = (rGPFCON & 0xffcc) | (1<<5) | (1<<1); // PF0/2 = EINT0/2
rGPGCON = (rGPGCON & 0xff3fff3f) | (1<<23) | (1<<7); // PG3/11 = EINT11/19
pISR_EINT0 = (UINT32T)int0_int; // isrEINT0; pISR_EINT8_23 = (UINT32T)int11_int; // isrEINT11_19;
3
rEINTPEND = 0xffffff;
rSRCPND = BIT_EINT0 | BIT_EINT8_23; //to clear the previous pending states rINTPND = BIT_EINT0 | BIT_EINT8_23;
rEXTINT0 = (rEXTINT0 & ~((7<<8) | (0x7<<0))) | 0x2<<8 | 0x2<<0; rEXTINT1 = (rEXTINT1 & ~(7<<12)) | 0x2<<12; rEINTMASK &= ~(1<<11);
rINTMSK &= ~(BIT_EINT0 | BIT_EINT8_23); }
/***************************************************************** * name: int_test
* func: Extern interrupt test * comment:
* EINT0 --- SB202 EINT11 --- SB203
*******************************************************************/ void int_test(void) //中断测试函数 {
int nIntMode;
uart_printf(\
uart_printf(\
5.B-EDGE\\n\
uart_printf(%uart_printf(%uart_printf(\
int_init();
g_nKeyPress = 3;
// only 3 times test (for board test) while(g_nKeyPress&(g_nKeyPress<6)) // SB1202/SB1203 to exit board test {
4
nIntMode = uart_getkey(); switch(nIntMode) {
case '1':
uart_printf(\
// EINT0/2=low level triggered,EINT11=low level triggered rEXTINT0 = (rEXTINT0 & ~((7<<8) |(0x7<<0)))|0x0<<8 | 0x0<<0; rEXTINT1 = (rEXTINT1 & ~(7<<12)) | 0x0<<12; break; case '2':
uart_printf(\
// EINT0/2=high level triggered,EINT11=high level triggered rEXTINT0 = (rEXTINT0 & ~((7<<8)|(0x7<<0))) | 0x1<<8 | 0x1<<0; rEXTINT1 = (rEXTINT1 & ~(7<<12)) | 0x1<<12; break; case '3':
uart_printf(\
// EINT0/2=falling edge triggered, EINT11=falling edge triggered rEXTINT0 = (rEXTINT0 & ~((7<<8) | (0x7<<0))) | 0x2<<8 | 0x2<<0; rEXTINT1 = (rEXTINT1 & ~(7<<12)) | 0x2<<12; break; case '4':
uart_printf(\
// EINT0/2=rising edge triggered,EINT11=rising edge triggered rEXTINT0 = (rEXTINT0 & ~((7<<8) | (0x7<<0))) | 0x4<<8 | 0x4<<0; rEXTINT1 = (rEXTINT1 & ~(7<<12)) | 0x4<<12; break; case '5':
uart_printf(\
// EINT0/2=both edge triggered,EINT11=both edge triggered
5