CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
naren



Joined: 18 Nov 2016
Posts: 10

View user's profile Send private message MSN Messenger

error
PostPosted: Tue Nov 29, 2016 12:50 am     Reply with quote

I am using ccs compiler and firstly I get #device problem, Solved it then i get undefined identifier problem. How to solve it?

Code:
// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on
*/
#include "18F4550.h"
#device adc=10
#define seg_port LATD
#define seg_unit LATA.F0
#define seg_decade LATA.F1
#define seg_hundred LATA.F2
#define seg_thousand LATA.F3
unsigned int i=0,j=0,k=0;

void main(void)
{
   unsigned int value[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
   unsigned int count,num0,num1,num2,num3,num4;
   TRISA=0;      // Configure PortA as output port
   LATA=0;
   TRISD=0;      // Configure PortD as output port
   LATD=0;

   for(count=0;count<9999;count++)      // Counter from 0 to 9999
   {
      num0=count;

      num1=num0%10;         // Extract the value of unit digit
      num0=num0-num1;
      num0=num0/10;

      num2=num0%10;         // Extract the value of decade digit
      num0=num0-num2;
      num0=num0/10;
                 
      num3=num0%10;         // Extract the value of hundred digit
      num0=num0-num3;
      num0=num0/10;
                 
      num4=num0%10;         // Extract the value of thousand digit
      num0=num0-num4;
      num0=num0/10;
                 
      for(i=0;i<10;i++)      // Delay= ((5msx4)x10) = 200ms between two consecutive counts
      {
         
         seg_unit=1;seg_decade=0;seg_hundred=0;seg_thousand=0;      // Display unit digit
                        seg_port=value[num1];
                        Delay_ms(5);
                       
                        seg_unit=0;seg_decade=1;seg_hundred=0;seg_thousand=0;      // Display decade digit
                        seg_port=value[num2];
                        Delay_ms(5);
                       
                        seg_unit=0;seg_decade=0;seg_hundred=1;seg_thousand=0;      // Display hundred digit
                        seg_port=value[num3];
                        Delay_ms(5);
                       
                        seg_unit=0;seg_decade=0;seg_hundred=0;seg_thousand=1      // Display thousand digit
                        seg_port=value[num4];
                        Delay_ms(5);
      }
   }
}

_________________
naren
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Nov 29, 2016 1:13 am     Reply with quote

Start at the beginning. The original code had fuses set. You need to duplicate these:
Code:

/* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
#include "18F4550.h"
#fuses HS_PLL //HS oscillator with PLL enabled
#fuses NOWDT //Watchdog off
#fuses MCLR //enable MCLR
#fuses CPUDIV1 //CPU /1 from clock
#fuses PLL2 //PLL fed off OSC/2
//At this point CCS _[u]requires[/u]_ a clock statement. You don't tell us
//your crystal, but guessing from the settings you have an 8MHz crystal
//and are running the CPU at 48Mhz
#USE DELAY(clock=48MHz, USB_FULL)


Then your second problem is trying to talk to the port latch registers and tris registers. CCS does not 'know' these names. You can define them, but easier to change the code to use the CCS commands:

Code:

//TRISA=0; // Configure PortA as output port
//LATA=0;
//TRISD=0; // Configure PortD as output port
//LATD=0;
output_a(0); //sets port a as output, and puts 0 into the latch
output_d(0); //same for port d


Similarly where you #define seg_decade for example, this needs to just have the pin name. So:

#define seg_decade PIN_F1

and when you want to set this to zero:

output_low(seg_decade);

Just about every line will need a change like this.
naren



Joined: 18 Nov 2016
Posts: 10

View user's profile Send private message MSN Messenger

thanks
PostPosted: Tue Nov 29, 2016 2:29 am     Reply with quote

thanks, i will try correct it
_________________
naren
naren



Joined: 18 Nov 2016
Posts: 10

View user's profile Send private message MSN Messenger

almost
PostPosted: Tue Nov 29, 2016 5:40 am     Reply with quote

I done the correction but still have 4 more error [undefined identifierPIN_D].
Code:

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on
*/


#include <18f452.h>
#include <string.h>
#USE DELAY (CLOCK=4000000)
#FUSES XT, NOWDT, NOPROTECT, DEBUG
#fuses NOWDT //Watchdog off
#define seg_port PIN_D
#define seg_unit PIN_A0
#define seg_decade PIN_A1
#define seg_hundred PIN_A2
#define seg_thousand PIN_A3
#USE DELAY(clock=48MHz, USB_FULL)

unsigned int i=0,j=0,k=0;

void main(void)
{
   unsigned int value[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
   unsigned int count,num0,num1,num2,num3,num4;

   output_a(0); //sets port a as output, and puts 0 into the latch
   output_d(0);

   start:if(input(PIN_C0)){   //PIN CO to start program
   for(count=0;count<9999;count++)      // Counter from 0 to 9999
   {
      num0=count;

      num1=num0%10;         // Extract the value of unit digit
      num0=num0-num1;
      num0=num0/10;

      num2=num0%10;         // Extract the value of decade digit
      num0=num0-num2;
      num0=num0/10;
                 
      num3=num0%10;         // Extract the value of hundred digit
      num0=num0-num3;
      num0=num0/10;
                 
      num4=num0%10;         // Extract the value of thousand digit
      num0=num0-num4;
      num0=num0/10;
                 
      for(i=0;i<10;i++)      // Delay= ((5msx4)x10) = 200ms between two consecutive counts
      {
         
         output_high(seg_unit);output_low(seg_decade);output_low(seg_hundred);output_low(seg_thousand);      // Display unit digit
                        seg_port=value[num1];
                        Delay_ms(5);
                       
                        output_low(seg_unit);output_high(seg_decade);output_low(seg_hundred);output_low(seg_thousand);      // Display decade digit
                        seg_port=value[num2];
                        Delay_ms(5);
                       
                        output_low(seg_unit);output_low(seg_decade);output_high(seg_hundred);output_low(seg_thousand);      // Display hundred digit
                        seg_port=value[num3];
                        Delay_ms(5);
                       
                        output_low(seg_unit);output_low(seg_decade);output_low(seg_hundred);output_high(seg_thousand);      // Display thousand digit
                        seg_port=value[num4];
                        Delay_ms(5);
      }
   }
}

if (input(PIN_C1)){              //TO reset the stopwatch
      output_d (0x3F) ; //display will show a 0
      output_a (0x3F) ; //display will show a 0
           i=0;
           j=0;
           k=0;
      goto start;}
      }

_________________
naren
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 29, 2016 5:58 am     Reply with quote

hmm..
#define seg_port PIN_D
#define seg_unit PIN_A0

PIN_D is 'not defined', means the compiler has no idea what it is.

I'll assume you ment to type PIN_D0 or PIN_D1 and 'lost' the number after the 'D'.


also

this

goto start;}

a LOT of hard core C programmers will say this is 'wrong', though perfectly acceptable and runs fine.
the 'goto' is not liked by most C guys.
The accepted method is to use the

do...
..
...
..
while()...

structure.

The irony to me is that BOTH methods result in a machine code GOTO instruction !

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Nov 29, 2016 6:04 am     Reply with quote

Yes.

In this case.

The reason it is deprecated, is that using the goto makes it possible to jump out of or into a section of code and leave the stack imbalanced. It's a way of potentially shooting yourself in the foot, so 'why use it'. There are a few occasions where it is the best solution, and it should only really be used for these....
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 29, 2016 6:36 am     Reply with quote

hmm, hadn't thought about the stack stuff....
wonder if the compiler could be made smarter to clean up the stack when a goto was used?
I know the MS BASIC interpreter for the TRS80s did

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group