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.

Hi-tech picc-18 pro _delay() bug

Status
Not open for further replies.

belesci

Newbie level 3
Joined
Dec 18, 2005
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
_delay

In PICC18 user manual it's writen _delay() inline function argument is unsigned long but if you check below 3 examples there is something wrong

exam 1 correct,
#include <pic18.h>
void main(void)
{
_delay(770);
}
code generated
143 003FF2 _main:
144 opt stack 31
145 ; BSR set to: ?
146 003FF2 FFFF dw 65535
147 003FF4 0E00 movlw 0
148 003FF6 u667:
149 003FF6 2EE8 decfsz wreg,f,c
150 003FF8 D7FE goto u667
151 003FFA D000 nop2 ;nop
154 003FFC EF00 F000 goto start
/******************************************************/
exam 2 wrong,

#include <pic18.h>

void main(void)
{
_delay(771);
}
code generated
143 003FF4 _main:
144 opt stack 31
145 ; BSR set to: ?
146 003FF4 FFFF dw 65535
147 003FF6 0E01 movlw 1
148 003FF8 u667:
149 003FF8 2EE8 decfsz wreg,f,c
150 003FFA D7FE goto u667
152 ; BSR set to: ?
153 003FFC EF00 F000 goto start
/*******************************************************/
exam 3 wrong,
#include <pic18.h>

void main(void)
{
_delay(5771);
}
code generated
143 003FEC _main:
144 opt stack 31
145 ; BSR set to: ?
146 003FEC FFFF dw 65535
147 003FEE 0100 movlb 0 ; () banked
148 003FF0 51FF movf ??_main& (0+255),w,b
149 003FF2 0E7C movlw 124
150 003FF4 u667:
151 003FF4 2EE8 decfsz wreg,f,c
152 003FF6 D7FE goto u667
153 003FF8 2FFF decfsz ??_main& (0+255),f,b
154 003FFA D7FC goto u667
156 ; BSR set to: ?
157 003FFC EF00 F000 goto start

What is wrong ? Is it bug or something missed ?
Thanks for interesting.
 

aProgrammer

Full Member level 2
Joined
Mar 29, 2001
Messages
149
Helped
23
Reputation
44
Reaction score
13
Trophy points
1,298
Location
Syldavia
Activity points
611
picc18 inline

Look at the _delay's definition.

Have you specified the running frequency
of your PIC18 ?
 

belesci

Newbie level 3
Joined
Dec 18, 2005
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
_delay hi-tech c

Running frequency is necessary for PICC-18 STD version.

For PRO version, _delay() generating number of cycles.

Here is PICC-18 PRO manual description,

Description
This is an inline function that is expanded by the code generator. When called, this routine expands
to an inline assembly delay sequence. The sequence will consist of code that delays for the number
of cycles that is specified as argument. The argument must be a literal constant.

Example
#include <htc.h>
void
main (void)
{
control |= 0x80;
_delay(10); // delay for 10 cycles
control &= 0x7F;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top