static global variables showing proper value + 1024

General discussion on mikroC.
Post Reply
Author
Message
stanigator
Posts: 47
Joined: 01 Nov 2007 19:32

static global variables showing proper value + 1024

#1 Post by stanigator » 28 Dec 2007 04:05

Below is my RTCcustom.c file:

Code: Select all

// RTCcustom.c                         <stanigator@gmail.com>
// Created: Dec 24, 2007
// Modified: Dec 26, 2007
// This contains function definitions of Real-Time Clock handling
// routines on DS1302 chip

#include "typedefs.h"
#include <built_in.h>
#include "RTCcustom.h"

static unsigned short *port;      // port that contains PIC port controlling RTC
static unsigned short pinIO = 0;       // pin on port controlling data pin of RTC
static unsigned short pinCE = 0;       // pin on port controlling clock enable pin of RTC
static unsigned short pinSCLK = 0;    // pin on port controlling SPI clock of RTC

void setRTCpin( unsigned short *RTCport,
              unsigned short IOpin,
              unsigned short CEpin,
              unsigned short SCLKpin)
{
     port = RTCport;
     pinIO = IOpin;
     pinCE = CEpin;
     pinSCLK = SCLKpin;
}

unsigned int MPORTreturn(void)
{
    return (int) &port;
}

unsigned short MIOreturn(void)
{
      return pinIO;
}

unsigned short MCEreturn(void)
{
      return pinCE;
}

unsigned short MSCLKreturn(void)
{
      return pinSCLK;
}

I have a main driver source code called dls.c calling setRTCpin() from RTCcustom.c file as shown below:

Code: Select all

// Data Logging Scale                 <stanigator@gmail.com>
// Created: Nov 3, 2007
// Revised: Dec 27, 2007

#include <built_in.h>
#include "typedefs.h"
#include "LCD4.h"
#include "RTCcustom.h"

#define BUFFER_SIZE 10

void delay(uint number)
{
      while(--number > 0);
}

void main() {
  char text_array[BUFFER_SIZE];       // array carrying text
  int n;                              // counter for data to text conversion

  OSCCON = 0x70;        /* internal oscillator at 8 Mhz, system clock = internal oscillator*/
 	OSCTUNE = 0x00;        /* oscillator tuning register at max frequency */
 	CMCON = 7;              // turn off comparators
 	Delay_ms(20);            // system wide delay of 20 ms
 	
  ADCON1 = 0x0e;          // Configure Vref and AN0
  TRISA  = 0x01;          // PORTA is output except RA0 (AN0)
  TRISB  = 0x00;          // all PORTB pins are output
  TRISC  = 0x00;          // PORTC is outputs
  
  LCD4_INIT();            // initialize the LCD
  setRTCpin(&PORTA, 1, 2, 3);

  while(1)
  {

     // Convert Real-time Clock Data Pin from data to text
     n = sprintf(text_array, "%u", MIOreturn());
     
     // exit execution if the conversion contains an error
     // making n == NULL
     if (n < 0 || n >= BUFFER_SIZE)
     {
        break;
     }
  
     LCD4_CMD(128);
     LCD4_OUT(text_array);
     LCD4_OUT("   ");
     
     // Convert Real-time Clock chip enable Pin from data to text
     n = sprintf(text_array, "%u", MCEreturn());

     // exit execution if the conversion contains an error
     // making n == NULL
     if (n < 0 || n >= BUFFER_SIZE)
     {
        break;
     }

     LCD4_CMD(134);
     LCD4_OUT(text_array);
     LCD4_OUT("   ");
     
     // Convert Real-time Clock SPI Clock Pin from data to text
     n = sprintf(text_array, "%u", MSCLKreturn());

     // exit execution if the conversion contains an error
     // making n == NULL
     if (n < 0 || n >= BUFFER_SIZE)
     {
        break;
     }

     LCD4_CMD(140);
     LCD4_OUT(text_array);
     LCD4_OUT("   ");
     
     /*// Convert Real-time Clock Port address from data to text
     n = sprintf(text_array, "%u", MPORTreturn());

     // exit execution if the conversion contains an error
     // making n == NULL
     if (n < 0 || n >= BUFFER_SIZE)
     {
        break;
     }

     LCD4_CMD(192);
     LCD4_OUT(text_array);
     LCD4_OUT("     ");*/
  }
}
However, what I'm seeing on the LCD output is what it's supposed to be but offset by 1024. Does anyone know why that may be the case? The project zip file is hosted in http://www.mediafire.com/?bj5bgdhbtgo if anyone is interested. Thanks for the comments in advance.

stanigator
Posts: 47
Joined: 01 Nov 2007 19:32

#2 Post by stanigator » 28 Dec 2007 06:50

Solved my problem. There was a signature mismatch between my RTCcustom.h and RTCcustom.c file. But now I have another problem. When I uncomment out the code that calls MPORTreturn() in dls.c, I'm not getting that address printed on the LCD properly. It only printed "21" on the LCD, which I infer that it's the address of port pointer in RTCcustom.c. If I replace the MPORTreturn() function call with &PORTA, the address of PORTA is printed on the LCD properly, but the pin numbers weren't printed properly. Does anyone know why this may be the case? Is it normal?

Post Reply

Return to “mikroC General”