Continue to Site

Need help with C code: cannot change value in loop

Status
Not open for further replies.

ZeleC

Full Member level 5
Full Member level 5
Joined
Dec 18, 2002
Messages
261
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,298
Activity points
2,173
C HElp

hello
ive been working on a pic16f873 and a led matrix 5x7,i simulated my models using proteus isis , and im using mplab combined with picc from hi-tech,
well i managed to put numbers on my matrix,and it worked great,until i tried to change the number example from one to two , i want to do it with a pointer, well im not that good with pointers!and arrays!!
here is my code and ill try to show you waht i have done:

#include <pic.h>
void DelayMs(unsigned char);
void Pause (unsigned char);
void DelayS(unsigned char cnt);

char const one[7] = {0x04,0x0C,0x14,0x04,0x04,0x04,0x1F};
char const two[7] = {0x0E,0x11,0x01,0x02,0x04,0x08,0x1F};
char const zero[7] = {0x0E,0x11,0x13,0x15,0x19,0x11,0x0E};
char const minus[7] = {0x0E,0x11,0x13,0x15,0x19,0x11,0x0E};
char *DigitPtr;
//char upmotion;
main(){
unsigned char dly = 25;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;

for(;;) {
*DigitPtr = one;
col = 0x01;
//DelayMs(50);
for (int i = 0 ; i < 7; i++){
PORTB = zero;
PORTC = ~position;
DelayMs(1);
col <<=1;}

}}

So this was working great ,i tried to make a pointer to hold the array that i want for example to replace the zero by one in my loop but it didnt worked ,
So any help from you guys on how to do that .
I hope you have understood what i mean so nayhelp???
thank you for your time .
 

Re: C HElp

Please use the 'code' button so we can see your indenting. It also avoids those unwanted smiley faces.

I don't have pic.h, so I changed several things so I could compile it without errors and warnings.

Code:
/* #include <pic.h> */

void DelayMs(unsigned char);
void Pause (unsigned char);
void DelayS(unsigned char cnt);

char const one[7] = {0x04,0x0C,0x14,0x04,0x04,0x04,0x1F};
char const two[7] = {0x0E,0x11,0x01,0x02,0x04,0x08,0x1F};
char const zero[7] = {0x0E,0x11,0x13,0x15,0x19,0x11,0x0E};
char const minus[7] = {0x0E,0x11,0x13,0x15,0x19,0x11,0x0E};
char const *DigitPtr;
/* char upmotion; */

int TRISA, TRISB, TRISC, PORTB, PORTC, col;

int main(void)
{
  int i;
  /* unsigned char dly = 25; */
  TRISA = 0x00;
  TRISB = 0x00;
  TRISC = 0x00;

  for(;;)
  {
    DigitPtr = one;
    col = 0x01;
    /* DelayMs(50); */
    for (i = 0 ; i < 7; i++)
    {
      PORTB = zero[i];
      /* PORTC = ~position[i]; */
      /* DelayMs(1); */
      col <<= 1;
    }
  }
  return 0;
}
On your compiler, try enabling maximum warnings. It helps catch bugs.

Your compiler should warn you about this suspicious assignment:
*DigitPtr = one;
Do this instead:
DigitPtr = one;

In C you can't declare a variable like this:
for (int i = 0 ; i < 7; i++)

Good luck!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top