I have this code, to check the status of a button.
The problem is that when I press the button it does not work. does not change state.
Code: Select all
/*
Author: Anilson Cardoso
Project: Button function
Date: December 1, 2010
*/
void main() {
ANSEL = 0x00; // Configure AN pins as digital
PORTA = 0x00; // all pins in PORTA are OFF
TRISA = 0x01; // All pins in PORTA are output except RA0
// binary order 0000 0001
do {
if(RA0_bit) //
{RA1_bit = 0;} // if bit RA0 is true then RA1 turns off
else
{RA1_bit = 1;} // if bit RA0 is false then RA1 turns On
} while(1);
}
RA0 is connected to a N.O. (Normally Open) Swicth and then to GND.
Why is that i can not detect the button?
I even tried to run some version
Code: Select all
/*
Author: Anilson Cardoso
Project: Button function
Date: December 1, 2010
*/
void main() {
ANSEL = 0x00; // Configure AN pins as digital
PORTA = 0x00; // all pins in PORTA are OFF
TRISA = 0x01; // All pins in PORTA are output except RA0
// binary order 0000 0001
PORTB=0x00;
TRISB=0xFF;
do {
if(RA0_bit) //
{RB1_bit = 0;} // if bit RA0 is true then RB1 turns off
else
{RB1_bit = 1;} // if bit RA0 is false then RB1 turns On
} while(1);
}
Can I have any help??
0 1 mikroCPIC1618.exe -MSF -DBG -pP16F688 -DL -O11111114 -fo8 -N"C:\Users\Anilson Cardoso\Documents\Electrical Circuit\Pic_Projects\Button.mcppi" -SP"C:\Program Files (x86)\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files (x86)\Mikroelektronika\mikroC PRO for PIC\Uses\P16\" -SP"C:\Users\Anilson Cardoso\Documents\Electrical Circuit\Pic_Projects\" "Button.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_B.mcl" "__Lib_EEPROM.mcl" "__Lib_FLASH_R.mcl" "__Lib_UART_c45.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_RS485.mcl"
0 1138 Available RAM: 240 [bytes], Available ROM: 4096 [bytes]
0 126 All files Preprocessed in 47 ms
0 122 Compilation Started Button.c
14 324 Undeclared identifier 'PORTB' in expression Button.c
15 324 Undeclared identifier 'TRISB' in expression Button.c
20 324 Undeclared identifier 'RB1_bit' in expression Button.c
22 324 Undeclared identifier 'RB1_bit' in expression Button.c
0 102 Finished (with errors): 02 Dec 2010, 04:13:46 Button.mcppi