how to code switch inputs for pic16f877a

Thread Starter

sheth_ka

Joined Sep 4, 2009
3
hi all,

can someone help me how to code switch or input on mikrobasic??i use pic16f877a microcontroller and i dont have any idea on how i could add switches on my project..actually i'm currently developing a count down timer (10min,20min,and 5min)..i need to add switches that will set 10min,20min,and 5min and switches that will control the pause and start of the time..i'm also new on using the mikrobasic..ive heard about the interrupts for mikrobasic,but i cant understand the syntax..hope you could help with my problem,thanks in advanced..:confused:
 

Thread Starter

sheth_ka

Joined Sep 4, 2009
3
First of all you have to switch off the analog staff (ADC & comparators) and this is accomplished setting these two registers:

ADCON1 = 7 ' All pins digital

CMCON = 7 ' All comparator Off


Then you must set the TRIS register (There is one for each port)

TRISA = %00000000 all portA pins set as output

TRISA = %11111111 all portA pins set as inputs


TRISB = %00000000 all portB pins set as output

TRISB = %00001111 First four bits set as output & last four bits set as inputs

You can use all the combination that you need to suite your application.

(The % stand for binary number in picbasic I don't know if mikrobasic has the same notation)

Once you have set the above registers you can start using your inputs or outputs.

Remember: NEVER LEAVE INPUTS PINS FLOATING. Always use pullups or pulldown resistor.

Also remember that the MCLR pin (reset pin) must always pulled up with a 10 K resistor.

Read the datasheet for your pic micro to learn more on the above registers.

Alberto
thanks for the reply..i will try that..
 
Top