Hi Fahmy,

RTFM ! Esp. 3.8 and 3.9.

Where is the ISR prototype in PROJECT1.C ?
Access to TICKS (why all CAPS?) is not made atomic.

Maarten

> Hi listers,
> 
> I have problems polling volatile variable from "extern" main(). Here are 
> details:
> 
> Compiler:
> =======
> I use this distribution: (output from "sdcc -v")
> SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 
> 2.5.6 #4264 (Jul  6 2006)
> 
> OS:
> ===
> Win2000
> 
> Chip:
> ====
> AT89S52
> 
> Simulator:
> =======
> JSIM 4.05 (Freeware from Jens Altmann)
> 
> Project files: (details are attached)
> =========
> sys.h
> sys.c
> project1.c
> project2.c
> 
> Commands: ( -L and -I paths are stripped)
> =========
> x:/>sdcc -c sys.c
> x:/>sdcc project.c sys.rel
> x:/>packihx project.ihx > project.hex
> 
> Problems:
> =======
> When I compiled the project1.c in modular way, with: ( -L and -I paths are 
> stripped)
> x:/>sdcc -c sys.c
> x:/>sdcc project1.c sys.rel
> polling volatile variable TIMEOUT from main() is failed.
> 
> When I merged "sys.h", "sys.c" in single file "project2.c" and do single 
> file compilation,
> x:\sdcc project2.c
> polling volatile variable TIMEOUT from main() is successfull.
> 
> Please anyone help me.
> I prefer modular compilation.
> I usually break source files in modules and build them with Borland's make.
> 
> Regards,
> Fahmy
> 
> 
> =====
> SYS.H
> =====
> #define XTAL               11.0592e6
> 
> #define TICK_PERIODE       50e-3
> #define RELOAD_VALUE       -( TICK_PERIODE * XTAL / 12 )
> #define TMOD_CONF          0x51                 // Timer 0: 16-bit timer, 
> Timer 1: 16-bit counter
> 
> // I stripped "extern" when I merged "sys.c" with "project2.c"
> extern void SystemTick     ( void ) interrupt 1 using 1;   // timer 0
> extern void LoadDelay      ( unsigned int ticks );
> extern void Delay          ( unsigned int ticks );
> extern void InitMcu        ( void );
> 
> volatile unsigned int  TICKS;           // system ticks
> volatile unsigned char TIMEOUT;         // system timeout flag
> 
> 
> =====
> SYS.C
> =====
> #include <at89x52.h>
> #include "sys.h"
> 
> void SystemTick( void ) interrupt 1 using 1 {
>      TR0 = 0;
>      TL0 = (unsigned char) RELOAD_VALUE;
>      TH0 = (unsigned char) ((unsigned int) RELOAD_VALUE >> 8);
>      TR0 = 1;
> 
>      /* system ticks */
>      if ( TICKS ) {
>          TICKS--;
>          return;
>      }
>      TIMEOUT = 1;
> }
> 
> void LoadDelay( unsigned int ticks ) {
>      if ( ticks ) {
>          TIMEOUT = 0;
>          TICKS = ticks;
>      }
> }
> 
> void Delay( unsigned int ticks ) {
>      LoadDelay( ticks );
>      while ( !TIMEOUT );
> }
> 
> void InitMcu( void ) {
>      // Initialize GLOBAL VARs here !
>      TICKS = 0;
>      TIMEOUT = 1;
> 
>      // External Interrupt Setting
>      IT0  = 0;       // falling edge for INT0
>      IT1  = 0;       // falling edge for INT1
> 
>      // Interrupt Priority Setting
>      PX0  = 0;       // Priority to INT 0
>      PT0  = 1;       // Priority to Timer 0
>      PX1  = 0;
>      PT1  = 0;
>      PS   = 0;
>   #ifdef AT89x52_H
>      PT2  = 0;
>   #endif
> 
>      // Enable specific interrupt(s)
>      EX0  = 0;       // External 0 interrupt
>      ET0  = 1;       // Timer 0 interrupt
>      EX1  = 0;       // External 1 interrupt
>      ET1  = 0;       // Timer 1 interrupt
>      ES   = 0;       // Serial interrupt
>   #ifdef AT89x52_H
>      ET2  = 0;       // Timer 2 interrupt
>   #endif
>      EA   = 1;       // Enable all interrupts
> 
>      // Timer Setup, see SYS.H
>      TMOD = TMOD_CONF;
> 
>      TL0 = (unsigned char) RELOAD_VALUE;
>      TH0 = (unsigned char) ((unsigned int) RELOAD_VALUE >> 8);
> 
>      TR0  = 1;       // run Timer0
> }
> 
> 
> ==========
> PROJECT1.C
> ==========
> #include <at89x52.h>
> #include "sys.h"
> 
> void main( void ) {
>      InitMcu();
> 
>      while ( 1 ) {
>          LoadDelay( 10 );
>          P1 = 0xff;              // leds off
>          while( !TIMEOUT );
>          LoadDelay( 10 );
>          P1 = 0;                 // leds on
>          while( !TIMEOUT );
>      }
> }
> 
> 
> ==================
> PROJECT2.C
> ==================
> #include "sys.c"
> 
> void main( void ) {
>      InitMcu();
> 
>      while ( 1 ) {
>          LoadDelay( 10 );
>          P1 = 0xff;              // leds off
>          while( !TIMEOUT );
>          LoadDelay( 10 );
>          P1 = 0;                 // leds on
>          while( !TIMEOUT );
>      }
> }
> 
> 



-------------------------------------------------------------------------
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
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to