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 support@ccsinfo.com

SEQUENCE expected is not there in hardware output

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



Joined: 31 May 2018
Posts: 5

View user's profile Send private message

SEQUENCE expected is not there in hardware output
PostPosted: Thu May 31, 2018 5:03 am     Reply with quote

Hi, 

I am new to pic controller programming. I have written a program to blink LED's in sequence which are connected to PORT B in PIC16F886. In MPLAB and the compiler is CCS. Hex is generated without any errors. But when i executed in hardware only one LED IS BLINKING. I want 1st LED to blink at 1 sec, second one at 1.5sec and third one at 2 sec. 

I am using timer 0 as counter(8 bit). Please help me. Thanks in advance. 
here is the program. 
Code:

#define _LEGACY_HEADERS
#include <16F886.h>
#include <stdio.h>
#include <math.h>
#include <float.h>

//__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO );
#define T0IF=0;
#define TOIE=1;
#define CMCON0 = 7; // disable compaarator
#define ANSEL = 0; // disable analog channel
#define PEIE = 1; // Enable peripherial interrupts and start processing
#define GIE = 1;
#define SYS_FREQ (8000000L) // System frequency
#define INTCON = 0;
#define TRISB= 00111000; //initialise the input and output terminals for PORT B
#define high_start 76; // high start used for timer0 overflow
int count;
void clock_isr();

void main(void)
{
count=0;
#define T0SE = 0; // falling edge selected
#define T0CS = 1; // Internal clock selected (timer mode ON)
#define PSA = 0; // Prescaler is assigned to the Timer0 module
#define TMR0ON = 1; // Turn ON the timer
#define T0PS0 = 1; // Prescalar values
#define T0PS1 = 1; // Prescalar values
#define T0PS2 = 1; // Prescalar values
output_bit(PIN_B0,0); //START_delay is OFF
output_bit(PIN_B1,0); //Integrator_delay is OFF
output_bit(PIN_B2,0); // soft_start_on is OFF

while(1)
  {
   clock_isr();

   // if count is 7812 decimal =1 sec / to put the hex value
   // in 16 bit,we need to initialise WDT timer
   if(count=7812) {
      output_bit(PIN_B0,1); //START_delay is ON
     }
   else if(count=11718) // if count is 11,718 decimal =1.5 sec
     {
      output_bit(PIN_B2,1); // soft_start_on is ON
     }
   else if(count=15624) // if count is15,624 decimal =2 sec
     {
      output_bit(PIN_B1,1); //Integrator_delay is ON
     }
  }
}
 
byte seconds, high_count;

#define INT_RTCC 0x000B20;  // Interrupt procedure
void clock_isr()
{
// called every time RTCC
high_count -= 1;  // flips from 255 to 0

if(high_count==0) {
   ++count;
   high_count=high_start;  // Inc SECONDS counter every
  }  // 76 times to keep time

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu May 31, 2018 11:45 am     Reply with quote

Lots of things are fundamentally wrong:
Code:

#define T0IF=0;
#define TOIE=1;
#define CMCON0 = 7; // disable compaarator
#define ANSEL = 0; // disable analog channel
#define PEIE = 1; // Enable peripherial interrupts and start processing
#define GIE = 1;
#define SYS_FREQ (8000000L) // System frequency
#define INTCON = 0;
#define TRISB= 00111000; //initialise the input and output terminals for PORT B
#define high_start 76; // high start used for timer0 overflow

Each of these does basically nothing. In C a #define is a text substitution macro. Nothing else. So the third line for example defines a text macro called 'CMCON0', which if you type it into the code will be replaced with '= 7'. Since you never type it, nothing at all is done....
So, the timer is never turned on. No interrupts are enabled. TRIS is never set. etc. etc.
Then you define the variable 'count' as a int. A int can hold 0 to 255. So it is never going to get to get to 7812, let alone 11718....

Read some of the CCS examples, and some of the code here. Use the CCS instructions to set the features you want.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 31, 2018 12:11 pm     Reply with quote

Quote:
#define INT_RTCC 0x000B20; // Interrupt procedure
void clock_isr()
{

Also, this is not how you tell the CCS compiler that clock_isr() is an RTCC
interrupt routine. Look in the CCS example file, Ex_dtmf.c. It shows
how to do it.


Quote:
#define high_start 76;

Another thing. You are placing a semi-colon (;) at the end of every
#define statement. This is not normally done in the C language.
You should stop doing it. It will cause compilation errors.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu May 31, 2018 12:27 pm     Reply with quote

The reason that hasn't given errors, is that since none of he defines is actually 'used', the substitution including the ; never actually takes place!.... Double ouch.
Roopa K



Joined: 31 May 2018
Posts: 5

View user's profile Send private message

PostPosted: Sun Jun 03, 2018 11:28 pm     Reply with quote

HI,

Thank you for the reply. I will make the changes and i will try
Roopa K



Joined: 31 May 2018
Posts: 5

View user's profile Send private message

PostPosted: Sun Jun 03, 2018 11:37 pm     Reply with quote

@Ttelmah

as Timer0 is also a 8 bit counter i have to use overflow flag setting. Is Count has to be defined as unsigned long int?
Roopa K



Joined: 31 May 2018
Posts: 5

View user's profile Send private message

errors in modified program
PostPosted: Mon Jun 04, 2018 12:57 am     Reply with quote

Hi,

I have changed my program according to suggestion. Now I am not using RTCC. In the new program i am facing some errors. Please help me to correct them.

following are the errors
>>> Warning 203 "led blinking.c" Line 36(1,1): Condition always TRUE
*** Error 58 "led blinking.c" Line 37(18,22): Expecting a close paren
*** Error 5 "led blinking.c" Line 54(12,13): Character constant constructed incorrectly
*** Error 5 "led blinking.c" Line 54(12,13): Character constant constructed incorrectly
*** Error 49 "led blinking.c" Line 54(12,13): Expecting LVALUE such as a variable name or * expression
*** Error 5 "led blinking.c" Line 54(15,17): Character constant constructed incorrectly
*** Error 5 "led blinking.c" Line 55(16,17): Character constant constructed incorrectly
*** Error 5 "led blinking.c" Line 55(16,17): Character constant constructed incorrectly
7 Errors, 1 Warnings.

The modified program is as follows
Code:

#define _LEGACY_HEADERS
#include <16F886.h>
#include <stdio.h>
#include <math.h>
#include <float.h>

//__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO );
#define T0IF'=0'
#define TOIE '=1'
#define CMCON0 '= 7'                              // disable compaarator
#define ANSEL '= 0'                           // disable analog channel
#define  PEIE '= 1'                            // Enable peripherial interrupts and start processing
#define GIE '=1'
#define SYS_FREQ (8000000L)                     // System frequency       
#define INTCON '= 0'
#define TRISB'= 00111000'                               //initialise the input and output terminals for PORT C   
#define T0SE '= 1'             // falling edge selected
#define T0CS '= 0'          // Internal clock selected (timer mode ON)
#define PSA '= 0'             // Prescaler is assigned to the Timer0 module
#define TMR0ON '= 1'         // Turn ON the timer
#define T0PS0 '= 1'           // Prescalar values
#define T0PS1 '= 1'            // Prescalar values
#define T0PS2 '= 1'           // Prescalar values       

void timercounter_ISR(void);             // function to increase  counter value
unsigned long count;
unsigned long high_count;
void timercounter_ISR(void);

void main(void)
{
count=0;
output_bit(PIN_B0,0);                //START_delay is OFF
output_bit(PIN_B1,0);               //Integrator_delay is OFF
output_bit(PIN_B2,0);             // soft_start_on is OFF

while(1)
  {
   timercounter_ISR(void);
   if(count==7812)                      // if count is 7812 decimal =1 sec      / to put the hex value in 16 bit,we need to initialise WDT timer 
     {
      output_bit(PIN_B0,1);                                   //START_delay is ON
     }
   else if(count==11718)                 // if count is 11,718 decimal =1.5 sec
     {
      output_bit(PIN_B2,1);                                  // soft_start_on is ON
     }
   else if(count==15624)               // if count is15,624 decimal =2 sec
     {
      output_bit(PIN_B1,1);                          //Integrator_delay is ON   
     }
  }
}

void timercounter_ISR(void)
{
while(!T0IF'=0');
output_bit(T0IF,0);
count++;
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Jun 04, 2018 2:54 am     Reply with quote

I've simply commented out all the lines which are causing errors.
I don't believe any of them are needed.

The program now compiles but not running as you expect.
(I don't have samples of your chip, but have run the code in MPLABSIM.)

For starters, you think you've set Timer to run, but it's not.

You are trying to set the registers with a load of #defines.
This is not the CCS way of doing things.

You need to look at some of the provided examples and learn from them.

Mike

PS Mr T. has also told you about the #defines. You have totally ignored his advice.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jun 04, 2018 4:51 am     Reply with quote

Knowledge is power !
You should look at several on the dozens of examples that CCS supplies, in the 'examples' folder. They will show you how to properly code in 'CCS style'.
Also if you press 'F11' while your project is open, the CCS manual will be shown on the screen, from there you can access a LOT of information CCS has including the FAQ section as well as links to some of the examples.
I understand English can be a very hard language to learn but a few hours reading the manual and most of it will make sense.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Jun 04, 2018 6:03 am     Reply with quote

He is also doing a new sillie:

output_bit(T0IF,0);

Duh. You can't 'output' to an internal register.
It isn't an internal register anyway. It is currently the text '=0'.

AArgh.
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