📄 gpio.c
字号:
/********************
www.21control.com
This Subprogram is the example how to use the GPIO and the extend interrupts.
*********************/
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_gpio.h>
#include <stdio.h>
#include <csl_irq.h>
void delay();
extern void VECSTART(void);
interrupt void Ext0Isr(void);
/*锁相环的设置*/
PLL_Config myConfig = {
0, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
1, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
17, //PLL multiply value; multiply 17 times
1 //Divide by 2 PLL divide value; it can be either PLL divide value
//(when PLL is enabled), or Bypass-mode divide value
//(PLL in bypass mode, if PLL multiply value is set to 1)
};
Uint16 IstFlag=0;
main()
{
/*初始化CSL库*/
CSL_init();
IRQ_setVecs((Uint32)(&VECSTART));
/*设置系统的运行速度为104MHz*/
PLL_config(&myConfig);
IRQ_globalDisable();
IRQ_plug(IRQ_EVT_INT0,&Ext0Isr);//外部中断0
IRQ_enable(IRQ_EVT_INT0);
IRQ_globalEnable();
GPIO_RSET(IODIR,0xFF);
while(1)
{
GPIO_RSET(IODATA,0xff);
asm(" RSBX XF");
delay();
delay();
GPIO_RSET(IODATA,0x87); //IO7
delay();
delay();
GPIO_RSET(IODATA,0x47); //IO6
delay();
delay();
GPIO_RSET(IODATA,0x17); //IO4
delay();
delay();
GPIO_RSET(IODATA,0x0f); //IO3
delay();
delay();
GPIO_RSET(IODATA,0x0);
asm(" SSBX XF");
delay();
delay();
}
}
void delay()
{
Uint32 j = 0,k = 0;
for(j = 0;j<10000;j++)
{
for(k= 0;k<100;k++)
{}
}
}
interrupt void Ext0Isr(void)
{
if(IstFlag==1)
{
IstFlag=0;
//asm(" RSBX XF");
//GPIO_RSET(IODATA,0x1);
}
else
{
IstFlag=1;
//asm(" SSBX XF");
//GPIO_RSET(IODATA,0x0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -