1942 views|0 replies

6570

Posts

0

Resources
The OP
 

About the basic operation of 28335 GPIO [Copy link]

GPIO is usually used for ordinary input and output, such as buttons, LEDs, or chip select segments, which are considered the most basic operations. Without further ado, let's just post the code + comments for future use. The board I use is the Yanxu Practical Board led.c #include "led.h" //LED and buzzer initialization void Led_Gpoi_Init(void) { EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 is reused as GPIO function GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // GPIO0 is set to output GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO1 = GPIO1 GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //GPIO0 is set to output GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; //Same configuration as above GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; // GpioCtrlRegs.GPADIR.bit.GPIO7 = 1; GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; //Buzzer GPIO settings, GPIO60 is multiplexed as GPIO function GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1; //Set to output LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 1;BUZZ_OFF EDIS; } led.h #ifndef LED_H_ #define LED_H_ #include "main.h" //According to the schematic diagram, the low level LED is on #define LED3 GpioDataRegs.GPADAT.bit.GPIO0 //Macro definition of LED data register #define LED4 GpioDataRegs.GPADAT.bit.GPIO1 #define LED1 GpioDataRegs.GPADAT.bit.GPIO6 #define LED2 GpioDataRegs.GPADAT.bit.GPIO7 #define BUZZ_OFFGpioDataRegs.GPBSET.bit.GPIO60=1; //Buzzer does not sound#define BUZZ_ONGpioDataRegs.GPBCLEAR.bit.GPIO60=1;//Buzzer soundsvoid Led_Gpoi_Init(void); #endif /* LED_H_ */ key.c #include "key.h" //Key IO port initializationvoid Key_Gpoi_Init(void) { EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;//Key GPIO setting, GPIO13 is multiplexed as GPIO functionGpioCtrlRegs.GPADIR.bit.GPIO13 = 0; //Set to input EDIS; } u8 KeyScan(void) { static u8 key_up=1;//Key press and release flagif( key_up&&(KEY0==0) ) //A key is pressed||KEY1==0||KEY2==0) { DELAY_US(10000);//de-bounce key_up=0; //Indicates that the key is not released if(KEY0==0) //KEY0 is pressed { return 1; } // else if(KEY1==0) // {return 2;} // else if(KEY2==1) // {return 3;}} } else if(KEY0==1)key_up=1; //&&KEY1==1&&KEY2==1 No key is pressed return 0;// No key is pressed } key.h #ifndef KEY_H_ #define KEY_H_ #define KEY0 GpioDataRegs.GPADAT.bit.GPIO13 #include "main.h" void Key_Gpoi_Init(void); u8 KeyScan(void); #endif /* KEY_H_ */ MAIN.C void main(void) { u8 key=0; //InitializationInitSysCtrl(); //Initialize system clock to 150M, turn off watchdog, and turn on peripheral clockInitGpio(); //Initialize GPIO to reset stateDINT; //Turn off CPU interruptInitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); //Initialize interrupt vector table//Peripheral configurationLed_Gpoi_Init(); //led port initializationKey_Gpoi_Init(); //Key IO initializationwhile(1) { key = KeyScan() ; //Scan keysswitch(key) //Make different responses according to key values{ case 1:LED1=0;break; case 2:....... ..... ....... } } } main.h #ifndef _MAIN_H #define _MAIN_H #include "DSP2833x_Device.h" // Headerfile Include File #include "DSP2833x_Examples.h" // Examples Include File #include "flash_ram.h" #include "led.h" #include "key.h" #include "extint.h" #include "timer.h" #include "sci.h" #include "pwm.h" #include "cap.h" #include "ad.h" #include "can.h" #include "spi.h" #include "NRF2401.h" #endif


This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list