Input to the PIC 16f84



Now that we learned how to get output form the PIC ( flashing LED ) , we ‘ll learn to input the

Microcontroller by a push button . This will give you an idea to get order from the user to do an

action ( open door, turn-off lights, ……… ) .


; Button.ASM
;******************************************************

list p=16f84

include “p16f84.inc”

org 0x00

goto start

org 0x20

start

bcf INTCON,7

movlw 0x00

bsf STATUS,5

movwf TRISA

bcf STATUS,5

movlw 0xFF

bsf STATUS,5

movwf TRISB

bcf STATUS,5

again

btfss PORTB,0

call LED_ON

call LED_OFF

goto again

LED_ON

movlw 0xFF

movwf PORTA

goto again

LED_OFF

movlw 0x00

movwf PORTA

goto again

end

;***********************************************

The program makes the LED is ON when the Button is pressed , LED off when Button is released.

The only new command here is BTFSS which checks if the button is pressed or released.

What it makes is Bit Test F Skip if Set where F is a bit in register. This command is a

bit-oriented command. It means it deals with one bit of the register.

Build the following circuit in Proteus 7 ISIS :


Follow the steps you learned before to add the source code to the circuit and configure it , then

start simulation. Of course in this time you ‘ll add the Button.ASM source code.

Now , we ‘ll write the same program in C

//******************************************************

#include”pic.h”

main()

{

unsigned char i;

TRISA = 0 ; // Make PORTB output

TRISB = 0xFF ; // Make PORTB input

PORTA = 0 ; // Initialize PORTB

for(;;) // This is the infinite loop that keeps the PIC running

{

if ( PORTB == 0 )

PORTA = 1;

else

PORTA = 0 ;

}

}

//************************************************************

Note that the logic is inverted because the button by default inputs one to the PIC and when pressed inputs zero.


Again , you can configure the project for the C source code from this lesson.

You can download the project files and source code from here.

Enjoy.

1 thought on “Input to the PIC 16f84

Leave a Reply

Your email address will not be published. Required fields are marked *