This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I'm using tiva launchpad. I succeed unlocking PF0 in a simple task to turn on and turn off led with SW0 (PF0). But when I attached that configure to my present project, it's not working. In my present project, I use PF4 to start the setting mode and update the setting(end setting mode). In setting mode, I use PF0 to increase the count and diplay the count to LCD. This is my code. Is there anything in my code affect to the PF0?
Thank you so much for your answers.
#include <stdint.h> #include <stdbool.h> #include <string.h> #include "inc/tm4c123gh6pm.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/systick.h" #include "driverlib/adc.h" #include "LCD.h" #include "Delay.h" #include "ADC.h" #define ADCTaskPeriod 7000 #define SW4TaskPeriod 50 #define SW0TaskPeriod 10 int ADCTimeCount=0; int ADCFlag=0; int SW0TimeCount=0; int SW0Flag=0; int SW4TimeCount=0; int SW4Flag=0; int SW4Install=0; uint8_t Temp; uint8_t LimitTemp,Count; //Hien thi nhiet do len LCD void Temp_Update(void) { int a,b; if (Temp<10) { SetCursor_LCD(2,10); LCD_data('0'); LCD_data(Temp+0x30); } else { a=Temp/10; b=Temp%10; SetCursor_LCD(2,10); LCD_data(a+0x30); LCD_data(b+0x30); } } //So sanh nhiet do do voi nhiet do cai dat int TempCheck() { if(Temp > LimitTemp) return 1; else return 0; } //Doc ADC, so sanh voi gia tri truoc, neu khac thi hien thi void ADCTask(void) { static int saveTemp; ADCProcessorTrigger(ADC0_BASE,3); Delay_ms(500); if (Temp != saveTemp) { saveTemp=Temp; Temp_Update(); } TempCheck(); if (TempCheck() == 1) GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3,1<<3); else GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3,0); } void SW4Task(void) { if (!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)) { if (SW4Install == 0) { SW4Install=1; SetCursor_LCD(1,3); LCD_WrStr(" "); SetCursor_LCD(1,0); LCD_WrStr("Cai dat: "); LCD_data(0xDF); LCD_data('C'); Count=0; } else { SW4Install=0; SetCursor_LCD(1,0); LCD_WrStr(" "); SetCursor_LCD(1,3); //Chinh con tro tai hang 1 vi tri thu 3 LCD_WrStr("Controller"); LimitTemp=Count; } } } void SW0Task(void) { if (!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)) { if (SW4Install == 1) { Count++; int a,b; if (Count<10) { SetCursor_LCD(1,10); LCD_data('0'); LCD_data(Count+0x30); } else { a=Count/10; b=Count%10; SetCursor_LCD(1,10); LCD_data(a+0x30); LCD_data(b+0x30); } } } } //Ngat Systick void SysTick_Int_Handler(void) { ADCTimeCount++; SW4TimeCount++; if (ADCTimeCount >= ADCTaskPeriod) { ADCTimeCount=0; ADCFlag=1; } if (SW4TimeCount >= SW4TaskPeriod) { SW4TimeCount=0; SW4Flag=1; } if (SW0TimeCount >= SW0TaskPeriod) { SW0TimeCount=0; SW0Flag=1; } } void ButtonConfig(void) { HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4|GPIO_PIN_0); GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); } int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); LCD_init(); ADC_init(); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ButtonConfig(); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_3); SysTickDisable(); SysTickPeriodSet(SysCtlClockGet()/1000); SysTickEnable(); SysTickIntRegister(SysTick_Int_Handler); SysTickIntEnable(); SetCursor_LCD(1,3); //Chinh con tro tai hang 1 vi tri thu 3 LCD_WrStr("Controller"); Delay_ms(20); SetCursor_LCD(2,0); LCD_WrStr("Nhiet do: "); LCD_data(0xDF); LCD_data('C'); Delay_ms(20); while(1) { if ( ADCFlag == 1) //Sau 7s cap nhat nhiet do 1 lan { ADCFlag=0; ADCTask(); } if (SW4Flag == 1) { SW4Flag=0; SW4Task(); } if (SW0Flag == 1) { SW0Flag=0; SW0Task(); } } }
Hi Charles,
I've answered similar questions from this poster - perhaps I can assist here, too...
Poster's code block follows:
void SW0Task(void)
{
if (!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0))
{
if (SW4Install == 1) // test # 1
{
Count++;
int a,b;
if (Count<10)
{
SetCursor_LCD(1,10);
LCD_data('0');
LCD_data(Count+0x30);
}
else
{
a=Count/10;
b=Count%10;
SetCursor_LCD(1,10);
LCD_data(a+0x30);
LCD_data(b+0x30);
}
}
}
}
Does your code reach to the "test #1" point I've identified? If so - your code has properly detected PF0.
Are you (really) sure that pin PF0 connects to a switch on the LPad? (I seem to recall that PF0 - due to its (nonsensical) NMI default - was avoided) [good that!]
Note too that the LPad's switch - or your "user supplied switch" may bounce - which will cause your variable "Count" to increment (many) more times than you desire. One simple cure is to delay w/in this function - so that the switch bounce interval has expired...
Your first job is to determine if you reach the indicated test point upon switch activation...
Greetings - if you "cannot reach Test Point #1" your issue may lie w/in hardware or software - or both.
Have you a scope (ideally) or a DMM - with which to monitor PF0 - both w/the proper (mating) switch, "actuated & un-actuated?" The signal level into PF0 should "swing" between the full 3V3 voltage levels.
Once that's been "test/verified" (kindly humor me - do this - even though you report (past) success) you must test to see if your "IF statement" (below) performs to your desire. Your IDE should enable you to monitor PF0 - which provides a "second - and independent confirmation" of PF0's being "pulled-up" (your code showed that) AND being responsive to "switch activation." (assumes that the LPad's switches "drive to ground."
Note: should the LPad's switch - tied to PF0 - "drive INSTEAD to VCC (3V3) when active" - you must alter PF0 to include a "WPD" not the "WPU" shown in your code! (WPD = weak pull-down resistor)
if (!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0))
Do keep in mind the tendency for most switches to "bounce" (i.e. "make & break contact" - sometimes lasting for several milliseconds.) You must "prevent" any "return" to that IF statement (now above) within the suspected "switch bounce interval." (via use of a delay)