[SOLVED] my pic18F4520 is not responding for any thing

Status
Not open for further replies.
Thank u ...very much can u just give the explanation for config of port bits bcz am a new user of MCU...i have read the data sheet many time but am not completely understanding..!
 

Take an example.

TRISA = 0b00000000; TRISA is the 8 bit register. 0b tells the compiler that we are using binary. 00000000 are the 8 bits set to 0 to make the PORTA as output port.

If TRISA = 0b11111111; then all the 8 pins of PORTA will be input ports.

you can use binary, hex or decimal for values.

TRISA = 0b00000000 is the same as TRISA = 0x00;

If only RA0 and RA1 are used as inputs. then TRISA = 0b00000011 which is equal to TRISA = 0x03;

CMCON = 0x07; or 0b00000111; means Comparaters are turned off and the 4 pins are made digital (Check the datasheet. I think RA0, RA1, RA2, RA3 are made digital.) D in the datasheet means digital. A for analog.

ADCON1 = 0b00001111; means all the AN pins are made digital i/o.

PORTB = 0x00; or 0b00000000; means all pins of portb are made low. i.e., 0 volts.

PORTB = 0b00000001; means the RB0 pin of PORTB is made high (5volts) and other pins low.
 
Last edited:
ADCON1 = 0b00001111; or 0x0F means AN pins are configured as digital i/o pins. Check the datasheet. In the ADCON1 configuration table, PCFG3 - PCFG0 should be 1111 if all AN pins have to be D or digital.
 

i have tried but LED's are not glowing...!when i have connected switch to RA3 some led's are glowing

- - - Updated - - -

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;
                      }
 
               }
       }
 }


i want the same switch to OFF the LED'
 
Last edited by a moderator:

This code is working. What value of current limiting resistors have you used for LEDs? Is your switches connected as shown in the image?

Code:
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;
                      }
               }
       }
}
 

Attachments

  • 6_led_v2.jpg
    214.5 KB · Views: 64
Last edited:

am using 1k resistors...switching is same as per the fig,,,

what config is this?
CVRCON.CVREN = 0;

- - - Updated - - -

still not getting any response...not getting proper result!!!!!!
 

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.
 

why we are using resistors in switches??,whats the software you using to design the circuit diagram??

thanks&Regards
srjth.m1
 
Last edited:

To limit the current. Without the resistor if you press the button the Vcc will be shorted to ground. The software is Proteus.
 

To limit the current. Without the resistor if you press the button the Vcc will be shorted to ground. The software is Proteus.

i have tried with the 330ohm resistor still itz not working ....
can we able to download the Proteus software???
 

May be there is some problem with your PIC. Are you using Internal Oscillator? Proteus you can download from labcenter.com.

In the download section there is a link for prodemo.exe. But with the demo version you cannot save files.

If you want the full version mail me @ internetuser2k11@gamil.com
 

Pic is working i have tried with a new one...am using an internal oscillator with 4mhz
 

circuit is given by you knw the same one..,am using two power supply for MCU and another for giving switch circuit!
 

Then it is working in simulation. May be some problem in your hardware.

Check the video
 

Attachments

  • sim1.rar
    33.2 KB · Views: 59
Last edited:

yes checked i understand ....i will check my hardware...Thanks alot.......

- - - Updated - - -


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;
                      }



can u just give an explanation??

- - - Updated - - -

when am giving a high to RA1 all LED's are blinking now.......!
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…