Hi there,
Trying to get into this whole PIC programming thing but hit an immediate brick wall a frustratingly simple one at that, which might explain why it's largely undocumented.
I'm using a Microchip PIC16F627 and a Velleman K8048 Pic Programmer. I'm writing my software using the MPLAB IDE v8.40 and the Hi-Tech C Compiler, then just use the Velleman software to upload the HEX files.
My problem is I can't seem to read any input from RA0..RA3, the 16F627 pins on which the K8048 switches are wired to.
I've looked over the assembler demos that came with the K8048 in case I was missing a step or two - the datasheet for the PIC in question mentions analogue functionality on PORTA and I certainly want them to be running in digital. I wondered if everything was set to analogue by default, but there is nothing in the assembler demo files to suggest a change is needed.
In assembler, reading RA0 after setting TRISA to 0b11111111 was achieved using:
Where SW1 was defined as hexadecimal '00'.
There's a lot of assembler there but I attempted to copy the gist of the input checking bits with the following bit of code. It's supposed to light an LED to make sure they're working, then light another if the switch input is detected:
I'm clearly doing it wrong, I just can't figure out what right is. Is the comparison between incorrect datatypes? Do I address the ports (i.e. RA0) directly?(tried it) Been trying for hours now, reading datasheets, googling hi-tech compilers and reading RA0/PORTA/just about everything. I can't seem to find a single simple example of reading a switch input for a PIC16f6xx?!!
Anyway I've got PORTB outputs down and have been making pretty patterns for a while, but if anyone thinks it might be easier to use PORTB for input too, let me know! I only want two LED outputs and three switch inputs, I have about eight bidirectional ports to play with on PORTB if I understand the datasheet.
I'd be very grateful for any code snippets of a simple "light an LED when a button is pressed" program at this stage
EDIT: Just to clarify, the observed response of the PIC when running this program is to light that first LED and then sit there no matter how many switches I mash.
Trying to get into this whole PIC programming thing but hit an immediate brick wall
I'm using a Microchip PIC16F627 and a Velleman K8048 Pic Programmer. I'm writing my software using the MPLAB IDE v8.40 and the Hi-Tech C Compiler, then just use the Velleman software to upload the HEX files.
My problem is I can't seem to read any input from RA0..RA3, the 16F627 pins on which the K8048 switches are wired to.
I've looked over the assembler demos that came with the K8048 in case I was missing a step or two - the datasheet for the PIC in question mentions analogue functionality on PORTA and I certainly want them to be running in digital. I wondered if everything was set to analogue by default, but there is nothing in the assembler demo files to suggest a change is needed.
In assembler, reading RA0 after setting TRISA to 0b11111111 was achieved using:
Code:
BTFSC PORTA,SW1
Where SW1 was defined as hexadecimal '00'.
There's a lot of assembler there but I attempted to copy the gist of the input checking bits with the following bit of code. It's supposed to light an LED to make sure they're working, then light another if the switch input is detected:
Code:
#include <htc.h>
#define SW1 = 0x00;
void main(){
[INDENT]TRISA = 1;
TRISB=0; //LEDs connected here
PORTB = 0x01; //just to prove LEDs operate (they do)
for(;;){
[INDENT]
if(PORTA == SW1){
[INDENT]
PORTB=0x02;
[/INDENT]
}
[/INDENT]
}
[/INDENT]
}
I'm clearly doing it wrong, I just can't figure out what right is. Is the comparison between incorrect datatypes? Do I address the ports (i.e. RA0) directly?(tried it) Been trying for hours now, reading datasheets, googling hi-tech compilers and reading RA0/PORTA/just about everything. I can't seem to find a single simple example of reading a switch input for a PIC16f6xx?!!
Anyway I've got PORTB outputs down and have been making pretty patterns for a while, but if anyone thinks it might be easier to use PORTB for input too, let me know! I only want two LED outputs and three switch inputs, I have about eight bidirectional ports to play with on PORTB if I understand the datasheet.
I'd be very grateful for any code snippets of a simple "light an LED when a button is pressed" program at this stage
EDIT: Just to clarify, the observed response of the PIC when running this program is to light that first LED and then sit there no matter how many switches I mash.
Last edited: