pic - PICkit2 flashing led with Button -
i using pickit2 low pin count demo board 16f690 chip. have been able write simple code turn leds on , off, upon trying utilize push button change state of leds, have been unable so. code below, along link schematic device.
#include <htc.h> __config(mclre_off & boren_off & pwrte_off & ieso_off & cp_off & fcmen_on); void main() { //initialization trisabits.ra3 = 1; //make button (ra3) input triscbits.rc0 = 0; //make led (rc0) output for(;;) // loop forever { //set rc0 if ra3 low (button pressed), else clear rc0 if(portabits.ra3) { rc0 = 1; } else { rc0 = 0; } } }
ra3 /mclr, table 3 of datasheet says pullup on pin activated external /mclr configuration. if there no pullup, won't changes. pin read continously high or low?
i'd avoid using ra3, @ least while debugging, , if have use in release code, swap pin 1 when debugging.
another common problem porta is default analog input port. ansel bits set, , need cleared used digital input, ra3 not mapped analogue input.
Comments
Post a Comment