Hello again, I just tested three variations of code both in my device and in gpsim. In the device I have two leds, one green which goes on when RA4 is zero and another orange which goes on when RB4 is zero (they go off when the respective bit is one). In all three variations the leds should go on (or RA4 and RB4 should be zero in gpsim).
In the variation #0 I simply put 0x00 in both LATA and LATB in order to
check whether the leds work. In variation #1 I test if the values of *p and
c are 0x12 and turn on each of RA4 and RB4 respectively. In variation #2 I
do the _same_ as in variation #1 except that the pointer is declared as
"data unsigned char *" instead of just "unsigned char *".
Variations #0 and #2 work fine on the device but variation #1 doesn't turn
any led on. Strangely, when testing variation #1 with gpsim it seems to work
fine (the command "symbol _PORTA" returns 0b00000000 and the same for
PORTB).
See bellow the main functions of the three variations. The rest of the
program before "main()" is in the end of this message.
Variation #0:
-=-=-=-=-=-=-=-
void main(void)
{
unsigned char c;
data unsigned char *p;
init();
LATA = 0x00; // turn on green led
LATB = 0x00; // turn on orange led
}
Variation #1:
-=-=-=-=-=-=-=-
void main(void)
{
unsigned char c;
unsigned char *p;
init();
c = 0x34;
p = &c;
*p = 0x12;
LATA = 0x10; // turn off green led
LATB = 0x10; // turn off orange led
if (*p == 0x12) LATA = 0x00; // turn on green led
if (c == 0x12) LATB = 0x00; // turn on orange led
}
Variation #2:
-=-=-=-=-=-=-=-
void main(void)
{
unsigned char c;
data unsigned char *p;
init();
c = 0x34;
p = &c;
*p = 0x12;
LATA = 0x10; // turn off green led
LATB = 0x10; // turn off orange led
if (*p == 0x12) LATA = 0x00; // turn on green led
if (c == 0x12) LATB = 0x00; // turn on orange led
}
Rest of the program (before "main()")
-=-=-=-=-=-=-= -=-=-=-=-=-=-=-=-=-=-=-
#include <pic18fregs.h>
#include <signal.h>
/* High priority interrupts
*/
DEF_INTHIGH(high_int)
DEF_HANDLER(SIG_TMR2, _tmr2_handler)
END_DEF
/* Low priority interrupts
*/
DEF_INTLOW(low_int)
DEF_HANDLER(SIG_TMR0, _tmr0_handler)
DEF_HANDLER(SIG_TMR1, _tmr1_handler)
DEF_HANDLER(SIG_TMR3, _tmr3_handler)
END_DEF
/* Timer0
*/
SIGHANDLER(_tmr0_handler)
{
/* Register must be cleared by software
*/
INTCONbits.T0IF = 0;
}
/* Timer1
*/
SIGHANDLER(_tmr1_handler)
{
/* Register must be cleared by software
*/
PIR1bits.TMR1IF = 0;
}
/* Timer2
*/
SIGHANDLER(_tmr2_handler)
{
/* Register must be cleared by software
*/
PIR1bits.TMR2IF = 0;
}
/* Timer3
*/
SIGHANDLER(_tmr3_handler)
{
/* Register must be cleared by software
*/
PIR2bits.TMR3IF = 0;
}
/* Initialization
*/
void init(void)
{
ADCON1 = 0x7f;
/* configure all PORTA pins as
* digital ports instead of analog
* A/D channels
*/
TRISA = 0x00;
/* configure all PORTA pins as
* output (output=0/input=1)
*/
LATA = 0x10;
/* Turns off R_LED (RA4) and put
* R_OUT1~4 to low (RA0~RA3)
*/
TRISB = 0x20;
/* configure all PORTB pins as
* output except for RB5 (IRD_IN)
*/
LATB = 0x10;
/* Turns off L_LED (RB4) and put
* L_OUT1~4 to low (RB0~RB3)
*/
RCONbits.IPEN = 1;
/* Enables priority levels on interrupts
*/
INTCONbits.GIE = 1;
/* Enables all high priority interrupts
*/
INTCONbits.PEIE = 1;
/* Enables all low priority peripheral interrupts
*/
INTCONbits.T0IE = 1;
/* Enables the TMR0 overflow interrupt
*/
PIE1bits.TMR1IE = 1;
/* Enables the TMR1 overflow interrupt (peripheral)
*/
PIE1bits.TMR2IE = 1;
/* Enables the TMR2 to PR2 match interrupt (peripheral)
*/
PIE2bits.TMR3IE = 1;
/* Enables the TMR3 overflow interrupt (peripheral)
*/
INTCON2 = 0xf0;
/* - All PORTB pull-ups disabled,
* - External interrupts 0, 1, 2
* on rising edges
* - TMR0 is set to low priority
* - RB port change interrupt is
* set to low priority
*/
IPR1 = 0x02;
/* - A/D converter interrupt set to low
* - EUSART receive interrupt set to low
* - EUSART transmit interrupt set to low
* - CCP1 interrupt set to low
* - TMR2 to PR2 match interrupt to HIGH
* - TMR1 overflow interrupt to low
*/
IPR2 = 0x00;
/* - Oscillator fail interrupt to low
* - Data EEPROM/Flash write operation interrupt low
* - Low voltage detect interrupt low
* - TMR3 overflow interrupt low
*/
T0CON = 0x43;
/* - Stops Timer0
* - Timer0 is configured as an 8bit timer/counter
* - Timer0 clock source is the internal
* instruction clock
* - Timer0 prescaler is assigned
* - 1:16 prescale value (4.096ms period)
*/
TMR0L = 0x00;
/* Reset Timer0
*/
T1CON = 0x00;
/* - Enables register read/write of
* Timer1 in two 8bit operations
* - System clock os derived from another source
* - 1:1 prescale value
* - Timer1 oscillator is shut off
* - Timer1 source is internal clock (Fosc/4)
* - Timer1 is stopped
*/
T3CON = 0x00;
/* - Enables register read/write of
* Timer3 in two 8bit operations
* - 1:1 prescale value
* - Timer1 is the clock source for
* compare/capture CCP module
* - Timer3 source is internal clock (Fosc/4)
* - Timer3 is stopped
*/
T2CON = 0x01;
/* - 1:1 postscale
* - Timer2 is off
* - Prescaler is 4
*/
}
I hope you don't mind that I attached the original files to this email (it
is just 3kb anyway...)
I will keep looking...
Guerra
On 1/18/07, Rodrigo Guerra <[EMAIL PROTECTED]> wrote:
Hi Raphael,
I compiled your code exactly as you said both in AMD64 and in an Intel
machine. I tried diff between both .hex files and they are identical. The
.lst files differed only in their time-stamps. The .cod files differed as
well, but I could not really tell what because those are binaries -- anyway,
with diff -a (to treat binary as text files) it seemed to do with the
time-stamp as well.
About gpsim, you were right, latest versions do support 18f1220 (I guess
they just didn't update the text file PROCESSORS...).
I reproduced your steps using gpsim just like you said (with both Intel
and AMD64 .cod files, just in case) and the result was identical.
Now I will go try the exact code I used in the device to see what gpsim
shows...
Cheers,
Guerra
On 1/17/07, Raphael Neider < [EMAIL PROTECTED]> wrote:
>
> Hi Rodrigo,
>
> > You said you tested with gpsim and I attempted to try as well but
> > gpsim (as of 0.22.0) seems not to support the PIC 18F1220 processor.
> > Apparently the only 16bit PIC it supports is 18Cxx2 but even this
> > seems to be not fully supported yet (accordingly to gpsim/PROCESSORS
> > in their sources).
>
> I use gpsim 0.21.12-pre (it may be an svn version, no official release);
> gpsim
> processor list
> quit
> reveals that the pic18f1220 is/was supported. [Update: Looked up and
> tried with the gpsim-0.22.0 release; also supports the pic18f1220, also
> yields the same good results on my IA32 box.]
>
> Then I feed my code (below again in full) using
> sdcc -mpic16 -p18f1220 -Wl,-m deref.c
> gpsim -i -s deref.cod
>
> (My actual sdcc invocation has more -I and -L paths specified, but these
> should not matter.)
>
> <code name='deref.c'>
> unsigned char glo;
>
> void main(void)
> {
> unsigned char c = 0x34;
> unsigned char *p;
>
> p = &c;
> *p = 0x12;
>
> glo = 0;
> if (*p == 0x12)
> glo = 1;
> if (*p == 0x34)
> glo = 2;
> if (c == 0x12)
> glo |= 4;
> if (c == 0x34)
> glo |= 8;
> }
> </code>
>
> Then I use the step command (step [Enter], [Enter], [Enter], ...) to
> obtain verbose output from the simulator, ignoring all warnings until it
>
> spins at the `bra $-0x0' instruction after having left main(). Scrolling
> back reveals that glo has been assigned 1 first and then its second bit
> has been set, indicating that both writing c via *p and reading back
> from both c and *p work nicely.
>
> Another way to obtain this result is to use the dump command after the
> simulator spins in the endless loop and look at memory locations
> 0x80..0x81 (according to my .map file, c goes to 0x80 and glo goes to
> 0x81). I find 0x80 holding 0x12 and 0x81 storing the desired value of
> 0x05.
>
> > Now I wonder if the problem could be more specific to certain types of
> > 16bit MCUs.
>
> Feel free to send me your .asm/.cod/.hex/.map/.lst files as generated by
>
> SDCC from the code above (or your failing test code)---maybe SDCC emits
> wrong code on AMD64?!? (Send these file to my personal mail account
> rather than the list, though.)
>
> > Which PIC did you use in your simulation?
>
> pic18f1220 as described above.
>
> Hope that helps,
> Raphael
>
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys - and earn cash
>
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sdcc-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>
--
Rodrigo da Silva Guerra
PhD Student
Department of Adaptive Machine Systems
Graduate School of Engineering
Osaka University - Japan
-- Rodrigo da Silva Guerra PhD Student Department of Adaptive Machine Systems Graduate School of Engineering Osaka University - Japan
sdcc-bug.tar.bz2
Description: BZip2 compressed data
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Sdcc-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sdcc-user
