Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 void main() { TRISA = 0b01111111; TRISB = 0b00000000; PORTB = 0b00000000;//here all B ports will go low knw ADCON1 = 0b00001111; CMCON = 0b00000111; while(1) { if(PORTA.F0 == 1) { Delay_ms(10); if(PORTA.F0 == 1) { PORTB.F0 = 1;//here will it goes high? } } if(PORTA.F1 == 1) { Delay_ms(10); if(PORTA.F1 == 1) { PORTB.F1 = 1; } } if(PORTA.F2 == 1) { Delay_ms(10); if(PORTA.F2 == 1) { PORTB.F2 = 1; } } if(PORTA.F3 == 1) { Delay_ms(10); if(PORTA.F3 == 1) { PORTB.F3 = 1; } } if(PORTA.F4 == 1) { Delay_ms(10); if(PORTA.F4 == 1) { PORTB.F4 = 1; } } if(PORTA.F5 == 1) { Delay_ms(10); if(PORTA.F5 == 1) { PORTB.F5 = 1; } } if(PORTA.F6 == 1) { Delay_ms(10); if(PORTA.F6 == 1) { PORTB.F0 = 0; PORTB.F1 = 0; PORTB.F2 = 0; PORTB.F3 = 0; PORTB.F4 = 0; PORTB.F5 = 0; } } } }
void main() {
int sw0, sw1, sw2, sw3, sw4, sw5;
TRISA = 0b01111111;
TRISB = 0b00000000;
PORTB = 0b00000000;
ADCON1 = 0b00001111;
CMCON = 0b00000111;
CVRCON.CVREN = 0;
CVRCON.CVROE = 0;
while(1) {
if(PORTA.F0 == 1) {
Delay_ms(30);
if((PORTA.F0 == 1) && (sw0 == 0)) {
PORTB.F0 = 1;
sw0 = 1;
}
else if ((PORTA.F0 == 1) && (sw0 == 1)) {
PORTB.F0 = 0;
sw0 = 0;
}
}
if(PORTA.F1 == 1) {
Delay_ms(30);
if((PORTA.F1 == 1) && (sw1 == 0)) {
PORTB.F1 = 1;
sw1 = 1;
}
else if ((PORTA.F1 == 1) && (sw1 == 1)) {
PORTB.F1 = 0;
sw1 = 0;
}
}
if(PORTA.F2 == 1) {
Delay_ms(30);
if((PORTA.F2 == 1) && (sw2 == 0)) {
PORTB.F2 = 1;
sw2 = 1;
}
else if ((PORTA.F2 == 1) && (sw2 == 1)) {
PORTB.F2 = 0;
sw2 = 0;
}
}
if(PORTA.F3 == 1) {
Delay_ms(30);
if((PORTA.F3 == 1) && (sw3 == 0)) {
PORTB.F3 = 1;
sw3 = 1;
}
else if ((PORTA.F3 == 1) && (sw3 == 1)) {
PORTB.F3 = 0;
sw3 = 0;
}
}
if(PORTA.F4 == 1) {
Delay_ms(30);
if((PORTA.F4 == 1) && (sw4 == 0)) {
PORTB.F4 = 1;
sw4 = 1;
}
else if ((PORTA.F4 == 1) && (sw4 == 1)) {
PORTB.F4 = 0;
sw4 = 0;
}
}
if(PORTA.F5 == 1) {
Delay_ms(30);
if((PORTA.F5 == 1) && (sw5 == 0)) {
PORTB.F5 = 1;
sw5 = 1;
}
else if ((PORTA.F5 == 1) && (sw5 == 1)) {
PORTB.F5 = 0;
sw5 = 0;
}
}
}
}
It is working fine in proteus and I am sure it works in real hardware. CVRCON.CVREN = 0; those 2 settings disables CVRef on RA2 pin.
Make the resistors 330 Ohms.
To limit the current. Without the resistor if you press the button the Vcc will be shorted to ground. The software is Proteus.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 if(PORTA.F0 == 1) { Delay_ms(30); if((PORTA.F0 == 1) && (sw0 == 0)) { //here sw=0 means switch off knw ?? PORTB.F0 = 1; sw0 = 1; } else if ((PORTA.F0 == 1) && (sw0 == 1)) { PORTB.F0 = 0; sw0 = 0; }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?