Hi, I am new to the field of PIC programming but trying to catch up. I need some help guys to write my code.
I have bought 12F508 and pins GP0 to 4 are pulled high by 10K with pushbuttons attached to the ground. I would like to have an shortest possible code to read the ports and send an serial command through GPIO.5 based on combinations of the buttons pressed. I have tried other ways using AND's but the PIC runs out of memory with this kind of approach.
I tried with the following but it's not working. I would like to know if the problem is with the code or my hardware. Once I make sure the code is ok then I will jump on to check the hardware settings.
I am little confused as to when I write i=gpio, does it stores i[0]=gpio.0 OR i[7]=gpio.0Code:define NO_CLRWDT 1 define OSC 4 ' OSCCON defaults to 4MHz on reset Include "modedefs.bas" @ __CONFIG _IntRC_OSC & _WDT_OFF &_MCLRE_OFF & _CP_ON Tx var GPIO.5 i var byte pause 50 main: ' Initialize the processor TRISIO = %011111 ' 1 bits are inputs - O are outputs Tx=0 ' Put Tx pin low OSCCAL = 0 PAUSE 50 start: while 1 i=gpio pause 500 if i=%11110 then ' if gpio.0 is pressed 'Serout............few bytes endif if i=%01110 then ' if gpio.0 + gpio.4 is pressed 'Serout............few bytes wend endif
Are the if statements above correct, I mean what will the PIC do with remaining 3 bits in i variable
Please help me understand how this will work. Thanks
Bookmarks