Hello there.
I just Want to know if this code will do what it is supposed to do (to scan input from portA, according to the input, sets a bit on output portB opposite to its current status)
If there is another way to scan input like a whole number (0111 for example) instead of (bit by bit 1,1,0,1). i didnt know how to make it interrupt driven input
and will this following part work without a problem?
Thanks for your help
I just Want to know if this code will do what it is supposed to do (to scan input from portA, according to the input, sets a bit on output portB opposite to its current status)
Rich (BB code):
#include <16F877A.H>
void init(void)
{
TRISA =0b00001111;
TRISB =0b00000000;
PORTA =0;
PORTB =0;
}
void main () {
void init(void);
while(true) {
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==0) && (PORTAbits.RA1==0) && (PORTAbits.RA0==1)) {
If (PORTBbits.RB0==0){
PORTBbits.RB0=1;
else
PORTBbits.RB0=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==0) && (PORTAbits.RA1==1) && (PORTAbits.RA0==0)) {
If (PORTBbits.RB1==0){
PORTBbits.RB1=1;
else
PORTBbits.RB1=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==0) && (PORTAbits.RA1==1) && (PORTAbits.RA0==1)) {
If (PORTBbits.RB2==0){
PORTBbits.RB2=1;
else
PORTBbits.RB2=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==1) && (PORTAbits.RA1==0) && (PORTAbits.RA0==0)) {
If (PORTBbits.RB3==0){
PORTBbits.RB3=1;
else
PORTBbits.RB3=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==1) && (PORTAbits.RA1==0) && (PORTAbits.RA0==1)) {
If (PORTBbits.RB4==0){
PORTBbits.RB4=1;
else
PORTBbits.RB4=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==1) && (PORTAbits.RA1==1) && (PORTAbits.RA0==0)) {
If (PORTBbits.RB5==0){
PORTBbits.RB5=1;
else
PORTBbits.RB5=0;
}
}
If ((PORTAbits.RA3==0) && (PORTAbits.RA2==1) && (PORTAbits.RA1==1) && (PORTAbits.RA0==1)) {
If (PORTBbits.RB6==0){
PORTBbits.RB6=1;
else
PORTBbits.RB6=0;
}
}
If ((PORTAbits.RA3==1) && (PORTAbits.RA2==0) && (PORTAbits.RA1==0) && (PORTAbits.RA0==0)) {
If (PORTBbits.RB7==0){
PORTBbits.RB7=1;
else
PORTBbits.RB7=0;
}
}
}
}
and will this following part work without a problem?
Rich (BB code):
If (PORTBbits.RB7==0){
PORTBbits.RB7=1;
else
PORTBbits.RB7=0;
}