Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

need help with my first PIC program

Status
Not open for further replies.

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
oscilloscope pic resonator troubleshoot

i am trying to make an LED blink as my first program.
my editor is: Microcode Studio
compiler: PIC Basic Pro 2.42
programmer: picall v0.013d

in microcode studio i loaded up the "blink.bas" as found in the pic basic pro samples directory. the program is about 6 lines. there are 2 instances where the command "pause" are used. i reasoned this is how the LED knows how long to turn on and off for. so i changed the line
from: PAUSE 500
to: PAUSE 3000

this will cause the LED to turn on and off for 3 seconds instead of 500mS. slowing it down allows me to verify voltage using my voltmeter, 500mS is too fast.

then i select the PIC chip i am using, a 16F877, and hit compile. within the picall software i load the compiled hex file and program my chip with success. verified OK.

i put my microchip in the circuit. the circuit on my bread board consists of 2 resistors, reset button, 20 MHz crystal, LED, and 2 caps, and some wires. the LED is connected from PORTB.0 to ground with a resistor.

when i apply power to the circuit nothing happens!

i checked the voltages and all seem proper. my supply with no load is 5.35v, when in circuit it drops to 4.65V. since the microchip's datasheet says it can operate from 2V-5.5V, i assume that this is OK.

i measure voltage at PORTB.0 to see if i can see the voltage, but it stays constant at 0.3v. infact, all of PORTB pins are at this constant voltage. the LED works fine, i have tested it.

what can be going wrong??? is it necessary for me to somehow tell the PIC chip that i am using a 20MHz crystal??? because i did not add this information in the code.

Mr.Cool
 

E-design

Advanced Member level 5
Joined
Jun 1, 2002
Messages
2,014
Helped
506
Reputation
1,014
Reaction score
407
Trophy points
1,363
Activity points
14,195
leonard zerman 16f877

Hi

Normally when you load the compiled program to the PIC you have an opportunity to select the osc type and speed.

I am using MPLAB and there you can select the osc and speed. I know that if you are not using the watchdog timer and forget to un-select that option the PIC will also hang.

Hope it helps!
 

GrandAlf

Advanced Member level 2
Joined
Mar 9, 2002
Messages
520
Helped
47
Reputation
92
Reaction score
6
Trophy points
1,298
Location
UK
Activity points
4,730
Are you sure that it is a 20mhz part and not 4 megs?
Have you setup the ports correctly?
Yes, Check watchdog disabled
Sounds like you are not using a regulator, you should be!

Finally, if you get a simulator, ISIS(proteus) is good, you can just draw it using active components, and then test.

I dont have PBPro at home, but if you are still stuck, I will write it for you when I get back to the office next week.
 

newmania

Member level 1
Joined
Sep 29, 2002
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
228
Please, write the complete code for help more. Like GrandAlf, I recommend to use proteus Isis to simulate the circuit. If it works at isis, try to verify code at picall software.
 

E-design

Advanced Member level 5
Joined
Jun 1, 2002
Messages
2,014
Helped
506
Reputation
1,014
Reaction score
407
Trophy points
1,363
Activity points
14,195
Also remember to make sure the PIC reset properly and verify that you have oscillations at 20MHz on the clock pins of the PIC with a scope.

Tip:
Some probes will load the clock pin enough to kill the oscillations. Use a 10k or so resistor in series with the scope probe to reduce the loading. It will also reduce the amplitude but you only want to know if it is oscillating at the right freq.
 

newmania

Member level 1
Joined
Sep 29, 2002
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
228
And a tip too: Use xtal osc. Because, rc oscylators aren't stable at time delays.
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
Thanks for all your help! Question: can proteous simulate Pic Basic code?? i have proteous but have never used it. unfortunately i am under the gun to get this pic chip stuff working, my thesis demands it and i have no ulternative. any help is appreciated.

using Microcode studio, when i open "blink.bas" i have this code displayed:

' Example program from manual to blink an LED connected to PORTB.0 about once a second

loop: High 0 ' Turn on LED connected to PORTB.0
Pause 3000 ' Delay for .5 seconds

Low 0 ' Turn off LED connected to PORTB.0
Pause 3000 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

that's it, that's alll it is. when i hit compile it produces an ASM file and a HEX file. the asm file is shown here:

; PicBasic Pro Compiler 2.42, (c) 1998, 2002 microEngineering Labs, Inc. All Rights Reserved.
PM_USED EQU 1

INCLUDE "16F877.INC"


; Define statements.
#define CODE_SIZE 8

RAM_START EQU 00020h
RAM_END EQU 001EFh
RAM_BANKS EQU 00004h
BANK0_START EQU 00020h
BANK0_END EQU 0007Fh
BANK1_START EQU 000A0h
BANK1_END EQU 000EFh
BANK2_START EQU 00110h
BANK2_END EQU 0016Fh
BANK3_START EQU 00190h
BANK3_END EQU 001EFh
EEPROM_START EQU 02100h
EEPROM_END EQU 021FFh

R0 EQU RAM_START + 000h
R1 EQU RAM_START + 002h
R2 EQU RAM_START + 004h
R3 EQU RAM_START + 006h
R4 EQU RAM_START + 008h
R5 EQU RAM_START + 00Ah
R6 EQU RAM_START + 00Ch
R7 EQU RAM_START + 00Eh
R8 EQU RAM_START + 010h
FLAGS EQU RAM_START + 012h
GOP EQU RAM_START + 013h
RM1 EQU RAM_START + 014h
RM2 EQU RAM_START + 015h
RR1 EQU RAM_START + 016h
RR2 EQU RAM_START + 017h
_PORTL EQU PORTB
_PORTH EQU PORTC
_TRISL EQU TRISB
_TRISH EQU TRISC
INCLUDE "BLINK2.MAC"
INCLUDE "PBPPIC14.LIB"


LABEL?L _loop
HIGH?C 000h
PAUSE?C 00BB8h
LOW?C 000h
PAUSE?C 00BB8h
GOTO?L _loop
END?

END

Question: why are there "?" marks in the code??? i open blink.asm with notepad, so it should be showing only pure ascii characters. as you can see in the assembly code the compiler aut0matically includes a file "16F877.inc". this consist of 16F877 setup information. incase it is relevant, i will include the contents of 16F877.inc here:

'****************************************************************
'* 16F877.BAS *
'* *
'* By : Leonard Zerman, Jeff Schmoyer *
'* Notice : Copyright (c) 1998 microEngineering Labs, Inc. *
'* All Rights Reserved *
'* Date : 10/23/98 *
'* Version : 2.11 *
'* Notes : *
'****************************************************************

BANK0 $0020, $007F
BANK1 $00A0, $00EF
BANK2 $0110, $016F
BANK3 $0190, $01EF
EEPROM $2100, $21FF
LIBRARY "PBPPIC14"
DEFINE CODE_SIZE 8

include "PIC14EXT.BAS"

PORTL VAR PORTB
PORTH VAR PORTC
TRISL VAR TRISB
TRISH VAR TRISC

include "PBPPIC14.RAM"

'*-----------------------* EOF 16F877.BAS *---------------------*

when i load up my programmer software, picall, i set the options as follows:
Oscillator: HS
Watchdog timer: OFF
BrownOut Detect: OFF

it also does not work with Watchdog timer: ON

Mr.Cool
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
i do not have a scope probe or oscilloscope in house so i am unable to determine if the problem exists with the crystal. all i know is that i bought it from a store a few days ago, specifically asked for 20MHz and its a tin can looking thing with 2 leads. there is a serial number on the top reads: T1C20MD36. i can do this test tomorrow if i bring everything to sk00l, if necessary.

Mr.Cool
 

newmania

Member level 1
Joined
Sep 29, 2002
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
228
You can use the hex file from picbasic. You musn't connect a ocs circuit to 16f877 in proteus. Look at sample circuits. If you dont want to use proteus, you can simulate it in microchip mplab. The basic code is true!
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
but how could this be a problem with the code? i mean the code is from the Pic Basic Pro "samples" directory. surely this is well tested.

Mr.Cool
 

newmania

Member level 1
Joined
Sep 29, 2002
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
228
I wanted to know, are portb pins pull-up?

The basic way:
Try to verify after programming the mcu via picall.
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
the program verifies OK within picall.

according to the datasheet Port B is:

PORTB is a bi-directional I/O port. PORTB can be software
programmed for internal weak pull-up on all inputs. The pull-ups are disabled on a Power-on Reset.

Mr.Cool
 

MCRF

Junior Member level 3
Joined
Apr 10, 2002
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
140
Blink LED

Try this:
------------------------------------------------------------
DEFINE OSC 20


Main: High Portb.0 ' Turn on LED connected to PORTB.0
Pause 3000 ' Delay for 3 seconds
Low Portb.0 ' Turn off LED connected to PORTB.0
Pause 3000 ' Delay for 3 seconds
Goto Main ' Go back to loop and blink LED forever
-------------------------------------------------------------

In picallw Chek Osc Type : XT or HS
Watchdog : On
Timer Up : On
Brown : On
LVP : Off
Fl.ProgMem Wtite : Off
Bacgra.Dbg : Off
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
MCRF, i have written the program to your instructions. i set the config options in picall to your specifications.

when i hit the Program button, it all seems to be normal until i get an error which reads:

Verify Error:
Fuses: buffer=3F6D device=3B7D

after i hit "OK" on the error it *does* say that the device was programmed successfully... so i move on.

pull out the chip and place it in my circuit breadboard.

again, nothin happens. i begin to wonder if its my oscillator. maybe its not oscillating? is there any way i can test this with only a voltmeter as a tool?

Mr.Cool
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
i just came across a post that said your oscillator is probably working if you measure 1.25v on the clockout pin, and definately not working if it measures 0 or 5V.

i measured 2.25V. i guess its working, not entirely sure.

Mr.Cool
 

Mr.Cool

Advanced Member level 2
Joined
Jun 20, 2001
Messages
664
Helped
87
Reputation
178
Reaction score
60
Trophy points
1,308
Activity points
7,113
just to make sure, i programmed a different 16F877. this time i did not get any FUSE verification error, so that's good.

when i put the new microchip into the circuit i did not get any blinking. :(

Mr.Cool
 

MCRF

Junior Member level 3
Joined
Apr 10, 2002
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
140
OK Mr.Cool

First you must setup:
PIC16F877

Check Vpp Voltage 13V on MCLR Pin PIC16F877

Incrase Prog Delay Value in Settings/Hardware_Setup


Write Manualy in Fuse/Prot. 3D75
And Pres Config Button
This is OK

Try it.
 

MCRF

Junior Member level 3
Joined
Apr 10, 2002
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
140
MCLR Pin - Reset Pin on PIC Must be 5V "1"

If "0" then PIC is Always in Reset State Chek this .

You Must Connect MCLR Pin over Pull-up resistor to Vcc (5V)
 

MCRF

Junior Member level 3
Joined
Apr 10, 2002
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
140
Chek Manualy yor LED Diode on +5V ?
Maybe wrong Polarity LED chek Anode/Cathode direction?

Oscilator Always work , you must check XT or HS oscillator
in Picall.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top