Hello Borut,
Thanks for the reply but pls see my second message. I misspelled the last
line in the email but it is correct in the program (I do use *p = 0x12).
I attached the full source for your reference this time. I use two LEDs to
debug my program in the device. I have one green LED in RA4 and another
orange LED in RB4. The green LED goes on with PORTA = 0x00 and goes off when
PORTA = 0x10. The same for the orange LED with PORTB.
With the attached source the green goes on. When I uncomment the *p = 0x12
line both LEDs remain off. I tested several times and I am sure both LEDs
are working ok and several other conditional tests worked fine. The
dereferenced read also seems to work okay (gptrget1.c).
PS.: This is a test application I wrote in order to narrow the problem I had
with the original program (which is much longer).
I am still stuck with this.
I feel like I will try to re-design my code so that I don't need to use
pointer dereferenced writing of values.
Let me know if you find something else strange with this...
Cheers,
Guerra
On 1/14/07, Borut Razem <[EMAIL PROTECTED]> wrote:
Rodrigo Guerra wrote:
> <snip>
> void main(void)
> {
> unsigned char c = 0x34;
> unsigned char *p;
>
> p = &c;
> p = 0x12;
>
> (...)
> <snip>
It should be:
*p = 0x12;
Borut
-------------------------------------------------------------------------
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
#ifndef SDCCpic16
#define SDCCpic16
#ifndef pic18f1220
#define pic18f1220
#endif
#endif
#include <pic18f1220.h>
/*#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)
*/
PORTA = 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)
*/
PORTB = 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
*/
return;
}
void change_value(unsigned char *pointer)
{
pointer[0] = 0x12;
}
void main(void)
{
unsigned char c = 0x34;
unsigned char *p;
init();
PORTA = 0x10;
PORTB = 0x10;
p = &c;
change_value(p);
// *p = 0x12;
if (*p == 0x34)
{
PORTA = 0x00; // green
}
if (*p == 0x12)
{
PORTB = 0x00; // orange
}
while (1);
}
-------------------------------------------------------------------------
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