PDA

View Full Version : hex file problem



engineer7
- 24th May 2011, 08:05
i have a very strange and one can say an ironic problem.


i have this simple code of checking led high:
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 5/22/2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic16F877a, WDT_OFF ' Watchdog Timer
@ DEVICE pic16F877a, PWRT_OFF ' Power-On Timer
@ DEVICE pic16F877a, BOD_OFF ' Brown-Out Detect
@ DEVICE pic16F877a, LVP_OFF ' Low-Voltage Programming
@ DEVICE pic16F877a, CPD_OFF ' Data Memory Code Protect
@ DEVICE pic16F877a, PROTECT_OFF ' Program Code Protection

DEFINE OSC 20

red_LED Var PortB.0

LOW red_LED

START:
HIGH red_LED
GOTO START
ok.now the hex it is generating i used proteus to check the led it is working fine in that.but when i burn the same hex file in my pic no 5v on picb.0. :( im a newbie in this.plz help me in this regard!

Archangel
- 24th May 2011, 08:43
Very first thing I see is a missing config for HS_OSC . . .
Then your loop never turns off the LED, and do not forget a pause so you can see it go off
or use the command toggle with a pause.

NOT REQUIRED with HIGH / LOW are tris registers as those statements automatically set tris
for you, But It is good practice to set port status first, then set tris to make ports inputs or outputs
in that order, like so
PortB = %00000000
TrisB = %10000000
in this case PortB.7 is unaffected by the tris, but all other PortsB are set low and then as outputs
That way when they become outputs they do so in the state you want them, in this case all low.

engineer7
- 24th May 2011, 09:12
thanks a lot sir.you saved my day.n i just wana ask one more think.it is that i am using PULSIN function.so for that particular function do i have to add any configuration fuses or not???

Archangel
- 24th May 2011, 09:44
Copy Paste from the book:

The resolution of PULSIN is dependent upon the oscillator frequency. If
a 4MHz oscillator is used, the pulse width is returned in 10us increments.
If a 20MHz oscillator is used, the pulse width will have a 2us resolution.

Defining an OSC value has no effect on PULSIN. The resolution always
changes with the actual oscillator speed.
PULSIN normally waits a maximum of 65535 counts before it determines
there is no pulse. If it is desired to wait fewer or more counts before it
stops looking for a pulse or the end of a pulse, a DEFINE can be added:
DEFINE PULSIN_MAX 1000
This DEFINE also affects RCTIME in the same manner.

‘ Measure high pulse on Pin4 stored in W3
PULSIN PORTB.4,1,W3

So the short answer is I do not think so, beyond the configs stated including the HS_OSC. I am guessing you have commented out the default configs in the 16F877A.inc file in PBP root directory.
Set up a word variable to store your results.
whatever number you get multiply by 2 micro seconds and that is your result at 20 mhz osc. Pulsin sets the tris like High / Low does.

engineer7
- 24th May 2011, 12:29
ok.got it.thanks a lot sir! :)