Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F452 Working Problem

Status
Not open for further replies.

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
Hey guys,
I have PIC18F452, I use QL2006 Programmer to program it, I really don't know what is the problem
I connected VCC, VSS, MCLR, 20Mhz crystal
and leds, the code is very basic just light leds on and off.
I burn the code and set the power, but nothing works, all the ports give 1.2 volt or 0 volt.


Is there any thing we need to set in the code, or the burning options ?!
 

Could be many things.

1. configuration bits wrong
2. watchdog timer causing reset
3. software bug
4. electrical problem.

Please post your schematic and code for more advice.

Brian.
 
One other thing: any port with analog capability (in particular PORTA and PORTE) will need to be switched to 'digital' mode.
Yet another 'thing': make sure that you have all of the by-pass capacitors in place.
What IDE and compiler are you using?
Susan
 
What is the right configuration bit setting for this PIC18F452
and how can I edit it in mkiroC
What are by-pass capacitors?
I use QL2006 Programmer software for burning the code, and Mikroc 6.5 for writing the code.
I double checked the electrical connections and wires, I'm sure it has something to do with configuration bits but don't know what ?!
 

The configuration bits depend on how you have the PIC connected. The list of settings in section 19 of the data sheet. If the configuration is set wrongly or not at all, there is a high probability the program will not run.

For a 20MHz crystal, using the in-built oscillator (not an external 20MHZ oscillator module) set the CONFIG1H register for HS oscillator and OSCSEN = 0.
CONFIG2L is up to you, for a simple program I suggest setting all bits to zero.
CONFIG2H I suggest you also set all bits to zero. This disables the watchdog which is probably OK in your program.
CONFIG3H just swaps a pin function and you are not using that function anyway so set it to zero.
CONFIG4L might be important. Bit 7 should be = 1, I suggest bit 0 = 0 and bit 2 depends on whether you are using high or low voltage programming mode. I have no idea what the QL2006 uses but making it = 0 is fine in most cases.
CONFIG5L is for making your code unreadable which is not important so set it to zero.
CONFIG5H is more protection. For now I suggest not proecting anything so make bit 6 = 1 and bit 7 = 1.
CONFIG6L again for now don't protect anything so set all bits = 1.
CONFIG6H more rotection bits, again you don't want protection so set all bits to 1.
CONFIG7L you probably are not using table reads so there is no need to protect them, set all bits to 1.
CONFIG7H this is really for situation where you need to protect bootloaders from being overwriten. It isn't really important but I suggest you set bit 6 = 1.
Ignore the DEVICEID registers.

Normally the CONFIG bits are set in your program and placed in the HEX file. I'm not sure if the QL2006 (I've never seen one) reads them from the hex file or you have to set them manually.

The bypass (aka decoupling) should be fitted directly across the VSS and VDD pins. You should have all the VSS and VDD pins connected, all are needed, they are not alternatives to each other. I suggest you use 100nF ceramic capacitors and connect them as close to the PIC as possible.

Brian.
 

Please zip and post your complete mikroC project files. I will set the config bits properly and post the modified project.
 

Please zip and post your complete mikroC project files. I will set the config bits properly and post the modified project.

Attached the design file and the code .c file using MikroC compiler
 

Attachments

  • 2222222.rar
    38.6 KB · Views: 77
  • malikRTC.rar
    5.4 KB · Views: 69

Are you using mikroC ? If yes, then zip and post the complete project files because the config bits are set in IDE (Edit > Edit Project...)
 

This is a link to download the full project file
It's created in MikroC, I'm trying to move it to MikroC pro but got few problems
 

Attachments

  • الكود.rar
    814.2 KB · Views: 73
Last edited by a moderator:

The download and save to my dropbox buttons are disabled at that link. Please zip and post the file here. I was unable to download from the dropbox link.
 

Attached the full code
Note that everything is working fine in simulation, but I can't get it to work in hardware, don't know what is the exact oscillator value for making this work !
the 7 segment blinks in real hardware
 

Attachments

  • الكود.rar
    814.2 KB · Views: 80

The project is not opening in mikroC 8.2. I viewed the code and it just contains RTC DS1307 code. If it is only RTC project then you can use any clock frequency.
 

The project is not opening in mikroC 8.2. I viewed the code and it just contains RTC DS1307 code. If it is only RTC project then you can use any clock frequency.

It is written in mikroc not mikroc pro
I tried many clock frequency they all work fine in simulation but not in hardware
 

I said I tried to open the project in mikroC 8.2. That is the non Pro version. What do you mean by it doesn't work in hardware ? LCD doesn't display anything ?
Please zip and post the complete mikroC project files which opens in mikroC.

The file from the proj.rar opened but Proteus file doesn't open. Please post the circuit in .png format. 5 ms timer is needed for 7 Segment display so that it doesn't flicker. How many 7 Segment displays are there in the circuit ?
 
Last edited:

I said I tried to open the project in mikroC 8.2. That is the non Pro version. What do you mean by it doesn't work in hardware ? LCD doesn't display anything ?
Please zip and post the complete mikroC project files which opens in mikroC.

The file from the proj.rar opened but Proteus file doesn't open. Please post the circuit in .png format. 5 ms timer is needed for 7 Segment display so that it doesn't flicker. How many 7 Segment displays are there in the circuit ?

Attached the proteus file and the code file in separated projects
There is no LCD in this, only 7 Segments, using multiplixing, the proteus file is created using proteus 7 so you can open the design file with proteus 8 by going to open > file > choose the type of file to by design file instead of project file and you will see a file called 222222 this is the design file and the simulation works just fine, the problem is with hardware

- - - Updated - - -

I said I tried to open the project in mikroC 8.2. That is the non Pro version. What do you mean by it doesn't work in hardware ? LCD doesn't display anything ?
Please zip and post the complete mikroC project files which opens in mikroC.

The file from the proj.rar opened but Proteus file doesn't open. Please post the circuit in .png format. 5 ms timer is needed for 7 Segment display so that it doesn't flicker. How many 7 Segment displays are there in the circuit ?

 

Attachments

  • Code.zip
    250 KB · Views: 61
  • design file.rar
    38.6 KB · Views: 60

The simulation doesn't work fine for me. In code it shows 8 MHz and in Proteus it is set to 20 MHz. In Proteus I see that displays light one after the other. I can only help you if you zip and post the Original untouched mikroC project files and Proteus file which show stable 7 Segment display.

Also in ISR there is
Code:
INTCON=0b00100000;
which is wrong. GIE is being disabled which turns off the timer0 interrupt. Without timer0 interrupt running you will not get display.
 

Here I am attaching the project. I migrated the code from mikroC to mikroC PRO PIC. I have compiled the code for 4 MHz external crystal. Burn my .hex file and test the working in hardware. In Proteus it is working that is there is no flickering of display. Don't use cracked compiler to compile the code. They generate wrong .hex file. The code is badly written, like

13 enable lines are used for 7 Segment displays but the 13th line never enables in ISR so the last two displays remain OFF all the time. Maybe somebody has tampered with the code.

They have used upper 4 bits of PORTB for buttons. They could have easily used RBIF to detect button presses but they have not.

In ISR for enabling displays, in while(1) loop for button press detection and for month selection they had used a lot of if() conditions. It is a very bad way of writing code. The PIC was executing all the if() conditions when only one if() condition had to be executed. So, to save PIC from doing unnecessary work I have replaced if() confitions with if...else if() conditions.

The project seems some ****** Calendar system. I don't know whether the code related to the calendar system is correct or not. If you explain what the system has to do, that is what things it has to display then I will write a better code.

If you post the original untouched project then I will modify it so that there will be no flickering of display.

Edit: I forgot configuring ADCON1. As Susan said it is very necessary as the PORTA lines connect to BCD to 7 Segment decoder. ADC functions has to be disabled. Put this

Code:
ADCON1 = 0x87;
in the first line of
Code:
void main()
 

Attachments

  • RTC DS1307 rev1.rar
    146.9 KB · Views: 68
Last edited:

In ISR they had used if() conditions instead of if...else if() conditions. Maybe it is because they wanted the ISR to take the same amount of time to execute irrespective of which if() condition is true..

Edit:

If the 2nd if() condition was executed in ISR then it doesn't matter how many other if() conditions are executed after it. So, it is good to use if...else if().

In the mikroC project you posted the GIE bit was cleared and TME0IF bit was not cleared in the ISR. According to that the 2 displays driven by x0 in Proteus file would be ON all the time after the first interrupt, assuming no other interrupt other than TMR0 interrupt occurs. After the 1st interrupt, no further interrupts (timer0) would occur. I don't know how you said that the displays work fine in Proteus but flicker in hardware.
 
Last edited:

In ISR they had used if() conditions instead of if...else if() conditions. Maybe it is because they wanted the ISR to take the same amount of time to execute irrespective of which if() condition is true..

Edit:

If the 2nd if() condition was executed in ISR then it doesn't matter how many other if() conditions are executed after it. So, it is good to use if...else if().

In the mikroC project you posted the GIE bit was cleared and TME0IF bit was not cleared in the ISR. According to that the 2 displays driven by x0 in Proteus file would be ON all the time after the first interrupt, assuming no other interrupt other than TMR0 interrupt occurs. After the 1st interrupt, no further interrupts (timer0) would occur. I don't know how you said that the displays work fine in Proteus but flicker in hardware.

Thanks for your help
First I have proteus 8 and I couldn't open the project file you attached could you save it as design file instead of project.

Regarding the new edits to the code you attached, please edit and generate a new hex for me since I don't have a paid version of MikroC pro would really appreciate that to try it and report back to you
 

I have not made any changes to the Proteus file. You can use your Proteus file for testing but change clock to 4 MHz. I have compiled code for 4 MHz external crystal and I have migrated the code to Pro version. I have only changed the Timer interrupt and timer0 initialization code. Burn my .hex file in hardware and tell me how it works, the display.

- - - Updated - - -

Also there is no button debounce delays. The buttons will not work properly.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top