Cantafford
Member
Hello everybody,
I'm building a timer and I wrote the following code:
When I try to compile it I'm recieving the following error:
undefined identifier "CMCON"
Here's are the error logs in case I missed to specify something.
I'm using PIC18f2580, that has a CMCON register. Here is the datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/39637b.pdf
Please help me correct this issue
. Thank you!
PS: Ignore the comments with questions from the code, it's a timer code that I've got from another site to include in a bigger project and I'm trying to understand it I noted what I should come back to later.
I'm building a timer and I wrote the following code:
Code:
/*
* File: mainfile.c
* Author: Paul
*
* Created on December 17, 2015, 6:37 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
void init(void); // done
void main(void); // partially done
void display(void); // partially done
void beep(void); // done
void bell(void);
unsigned char min, min10; // unsigned character min and min10
void main()
{
unsigned char sec, min2;
min = min10 = 0;
init(); // call the init function
for(; ;){TMR0 = 0; T0IF=0; display(); // DISPLAY(EXPAIN THIS PLEASE)
if(!PORTBbits.RB2) // if RA2==0 advance minute count
{
min++; // reset/minutes button
if(min==10) {min=0;}
TMR0=0; T0IF=0; // clear timer content and interupt flag(WHY?)
while(!PORTBbits.RB2) //while RA2==0(RA2 is pressed)
{
display(); // display as we set?????
if(T0IF) // if an interrupt has occured
{
T0IF=0; // clear the interrupt flag
min++; // increment minute by 1
if(min==10){min=0;} // do this
}
}
}
if(!PORTBbits.RB3) // if RA3 is pressed, advance minutes x10 count
{
min10++; // minutes x10 button
if(min10==10){min10=0;}
TMR0=0; T0IF=0;
while(!PORTBbits.RB3)
{
display();
if(T0IF)
{
T0IF = 0;
min10++;
if(min10==10) {min10=0;}
}
}
}
if(!PORTBbits.RB4 && (min || min10)) // if RA4(start button is pressed) and min or min10 == 1
{
TMR0 = 0; // clear TMR0 content's
sec = 0;
min2 = min+1;
beep(); // beep for a bit
while(1)
{
display(); // display
if(T0IF)
{
T0IF = 0;
++sec;
if(sec==60) {sec=0; --min2;} // minutes count
if(min2==0) {min2=10; --min10;}
}
min = min2 - 1;
if(!PORTBbits.RB2) // reset/minutes button
{
min = min10 = 0;
while(!PORTBbits.RB2) {display();}
break;
}
if(min==0 && min10==0) {bell(); break;}
}
}
}
}
void init(void)
{
CMCON = 0b11111111; //comparator off
T0PS0 = 0; T0PS1 = 0; T0PS2 = 1; // timer0 1:32 prescale value
TRISB = 0; //RB all outputs
TRISA = 0b11111100;
}
void display(void)
{
unsigned char digit[12];
digit[0]=0b111111;
digit[1]=0b110;
digit[2]=0b1011011;
digit[3]=0b1001111;
digit[4]=0b1100110;
digit[5]=0b1101101;
digit[6]=0b1111100;
digit[7]=0b111;
digit[8]=0b1111111;
digit[9]=0b1100111;
digit[10]=0b1110111; //7 segments for A
digit[11]=0b111000; //7 segments for L
PORTB=digit[min10];
LATBbits.LATB0=1; // transistor for cc1 is on(display PORTB[min10] here
__delay_ms(4);
LATBbits.LATB0=0; // the transistor for cc1 is off(no more value on cc1)
PORTB=digit[min]; // display this value
LATBbits.LATB1=1; // on cc 2
__delay_ms(4);
LATBbits.LATB1=0; // then no more value on it
}
void beep(void)
{
unsigned char i;
i=0;
while(i<60)
{ //duration of beep
LATBbits.LATB7=1; //buzzer output 800hz
_delay(1); // 1 sec delay
LATBbits.LATB7=0;
i++;
}
LATBbits.LATB7=0;
}
void bell(void)
{
unsigned char i, j;
i = 0;
min = 11; min10=10; // display AL
while(i<25) // rings
{
i++;
j = 0;
beep();
__delay_ms(100);
beep();
while(j<25)
{
j++;
display();
}
if(!PORTBbits.RB2)
{
while(!PORTBbits.RB2) {display();}
break;
}
}
min = 0; min10=0;
}
When I try to compile it I'm recieving the following error:
undefined identifier "CMCON"
Here's are the error logs in case I missed to specify something.

I'm using PIC18f2580, that has a CMCON register. Here is the datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/39637b.pdf
Please help me correct this issue
PS: Ignore the comments with questions from the code, it's a timer code that I've got from another site to include in a bigger project and I'm trying to understand it I noted what I should come back to later.