Vizier87
Active Member
Hi guys,
I know, I know, PIC16Fs are waaay outdated now but it's just a prototype and I'll be migrating to MSP430s soon so I just want to get some programming lessons here.
So... here's my UART program for a PIC1F877A:
And here's the memory org:
**broken link removed**
Basically I'm only trying to make it like this:
I press on my keypad (RA5 in this case) and an LED turns on, and at the same time transmits 0xFF.
When the keypad is not pressed, it's idle. Simple.
Here's two questions:
1. I managed to get the Tx output nicely using a Logic Analyzer, BUT the output comes out without me pressing the button!
2. I am a bit unsure about whether we need to switch banks when polling a bit from another bank when I'm in a different bank. I know if we need to SET or CLEAR the bit, the bankswitch is needed, but in this case I need some clarification.
So guys, dig in and thanks in advance.
Appreciate the time spent on this.
Vizier87
I know, I know, PIC16Fs are waaay outdated now but it's just a prototype and I'll be migrating to MSP430s soon so I just want to get some programming lessons here.
So... here's my UART program for a PIC1F877A:
C:
void main() {
/////////////////////////
rp1_bit=0; ////////
rp0_bit=1; //BANK 1
/////////////////////////
adcon1=0b00000111; //pcfg settings: all digital I/O
cmcon= 0b00000111; //comparators off
cvrcon=0; //voltage comparators off
txsta=0b00000100; //8-bit, Async mode, Hi-Speed, enable transmission
intcon=0b11000000; //enable all peripheral interrupts
spbrg=64; //19.231 kBps
txie_bit=1; //Tx int. flag enable
trise=0x07; //porte=input, pspmode_bit=0;
trisa=0b100000; //ra5=input
trisd=0xff; //rd4=input, rest output
trisb=0; //portb=output
trisc=0b10111111; //input for keypads and RX=input/TX=0utput
/////////////////////////
rp1_bit=0; ////////
rp0_bit=0; //BANK 0
/////////////////////////
pir1=0b11000000;
rcsta=0b10011100; // enable Rx/Tx, 8-bit, continuous,
//address detect, interrupt enable,
//framing error, no overrun
portb=0;
porta=0;
while (1){
/////////////////////////
rp1_bit=0; ////////
rp0_bit=0; //BANK 0
/////////////////////////
if (ra5_bit==1){
rb7_bit=1;
/////////////////////////
rp1_bit=0; ////////
rp0_bit=1; //BANK 1
/////////////////////////
if (txif_bit==1){
txen_bit=1;
txreg=0xff;
}
}
else {
/////////////////////////
rp1_bit=0; ////////
rp0_bit=1; //BANK 1
/////////////////////////
txen_bit=0;
/////////////////////////
rp1_bit=0; ////////
rp0_bit=0; //BANK 0
/////////////////////////
rb7_bit=0;
}
}
}
And here's the memory org:
**broken link removed**
Basically I'm only trying to make it like this:
I press on my keypad (RA5 in this case) and an LED turns on, and at the same time transmits 0xFF.
When the keypad is not pressed, it's idle. Simple.
Here's two questions:
1. I managed to get the Tx output nicely using a Logic Analyzer, BUT the output comes out without me pressing the button!
2. I am a bit unsure about whether we need to switch banks when polling a bit from another bank when I'm in a different bank. I know if we need to SET or CLEAR the bit, the bankswitch is needed, but in this case I need some clarification.
So guys, dig in and thanks in advance.
Appreciate the time spent on this.
Vizier87