Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] compiler cmcon=7; pic16 //LCD module connections

Status
Not open for further replies.

ana_cont

Junior Member level 2
Joined
Jun 15, 2020
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
11
Activity points
128
Code:
//LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
//end LCD module connections

#define PULSE PORTA.RA4

unsigned int Overflow;
unsigned char Cnt;
//
//Timer interupt service routine jumps here at every 10ms
//
void interrupt(void)
{
 if(INTCON.TMR0IF==1)            //If TIMER0 INTERRUPT
            {
                  Overflow++;     //Increment Overflow flag
                  INTCON.TMR0IF=0; //Clear timer0 interrupt flag
            }
 if(PIR1.TMR1IF==1)                //If timer1 interrupt
            {
                   TMR1H=0x0B;     //Reload timer register
                   TMR1L=0xDC;
                   Cnt++;          //Increment cnt
                   PIR1.TMR1IF=0;  //Clear Timer1 interrupt flag
            }
}



void main()
{
 unsigned char Txt[11];
 unsigned long Elapsed;
 unsigned char L_Byte, H_Byte;
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 0x07; // Disable comparators
 //ANSEL A =0;// 0; // Configure PORTA as digital
 //ANSEL B = 0; //
 TRISA.RA4 = 1; // RA4 is input
 Lcd_Init(); // Inialize LCD
 Lcd_Cmd(_LCD_CURSOR_OFF); // Disable cursor
//
 // Configure TIMER0 for 16-bit mode, no prescaler, clock provided by external
 // signal into pin T0CKI. Timer is not started here
 //
 T0CON = 0x28; // TIMER0 16-bit,no prescaler,T0CKI clk
//
// Configure Timer1 for 250 ms Overflow. Timer1 is not started here
//
 T1CON = 0x36;

 PIE1 = 0x01; // Enable TIMER1 interrupts
 PIR1.TMR1IF = 0; // Clear TIMER1 interrupt flag
 INTCON = 0xE0; // Enable TIMER0 and TIMER1 interrupts

 for(;;) // Wait for interrupts
 {
 TMR0H = 0; // Clear Timer0 registers
 TMR0L = 0;
 TMR1H = 0x0B; // Load Timer1 registers
 TMR1L = 0xDC;
 //
 Overflow = 0; // Clear Overflow count
 Cnt = 0; // Clear Cnt
 //
  // Start TIMER0. It will increment each me an external pulse is detected.
 // TIMER0 increments on the rising edge of the external clock
 //
 T0CON.TMR0ON = 1;
 //
 // Start Timer1 to count 4 × 250 ms = 1 s
 //
 T1CON.TMR1ON = 1;
 while(Cnt != 4); // Wait unl 1 s has elapsed
 //
 // 1 s has elapsed. Stop both mers
 //
 T0CON.TMR0ON = 0; // Stop TIMER0
 T1CON.TMR1ON = 0; // Stop Timer1
 // Get TIMER0 count
 L_Byte = TMR0L;
 H_Byte = TMR0H;
 //
 // Store TIMER0 count is variable Elapsed
 //
 Elapsed = (unsigned long)256 * H_Byte + L_Byte;
 Elapsed = 65536 * Overflow + Elapsed;
 //
 // Convert into string and display
 //
 LongWordToStr(Elapsed, Txt); // Long to string conversion
 Lcd_Cmd(_LCD_CLEAR); // Clear LCD
 Lcd_Out(1,1,"Frequency (HZ)"); // Display heading
 Lcd_Out(2,1,Txt); // Display measured frequency

 Delay_ms(1000); // Wait 1 s and repeat
 }
}
--- Updated ---

hI CMCON=7 ; NOT COMPILE
 
Last edited by a moderator:

hi​

thank you​

pic16f877
 

That explains the problem, the PIC16F877 does not have a CMCON register!
Only PICs with analog comparators have that register, you can probably remove the line from your program.

Brian.
 
hi brain proram compile ok, but simulation not
--- Updated ---

here ihave mix varible types of math:
Code:
int puls=0;
#define sw portd.rd0
void main(){
trisc=0x00;
portc=0;
trisd.f0=1;
if(sw==1)
while(sw==1);
pulse++;
}
if(pulse>=500)pulse=0;
if(rd0_bit==1)pulse++;
if(pulse==pulse<=51){
portc.f4=0;
}
while(1){
if(pulse>=52){
while(pulse==52);
pulse=pulse *(25/60);
pulse=0.8666667;
}
if(pulse>=0.8666667&&pulse<=125){
portc.f4=1;
}
help me which is wrong
--- Updated ---

52/60 not 25/60
 
Last edited by a moderator:

That explains the problem, the PIC16F877 does not have a CMCON register!
Only PICs with analog comparators have that register, you can probably remove the line from your program.

Brian.
t hank you very muct h
--- Updated ---

That explains the problem, the PIC16F877 does not have a CMCON register!
Only PICs with analog comparators have that register, you can probably remove the line from your program.

Brian.
thanks
--- Updated ---

That explains the problem, the PIC16F877 does not have a CMCON register!
Only PICs with analog comparators have that register, you can probably remove the line from your program.

Brian.
thanks
 

I added code tags to your code to preserve the original formatting.
I'm not sure exactly what your code is supposed to do but there is an error in the way you use 'pulse'. It is an integer (int) so it can only hold whole numbers, you are trying to hold a fraction in it. Most likely the fraction will be interpreted as '1' or '0', depending on the compiler but it certainly wont be 0.8666667 !

You could try changing:
Code:
pulse=pulse *(25/60);
to
Code:
pulse *= 25;  pulse /= 60;
to avoid fractional calculations but I would suggest trying to rewrite it to avoid fractions altogether.

Brian.
 

That code is a total mess - it cannot compile as written because there is at least one open brace ('{') missing, possibly after the 'if(sw==1)' line (but only guessing) and also at least 1 (and possibly 2) missing closing braces ('}').

The statement 'if(pulse == pulse <= 51)' is meaningless.

Logically the code is also bad. The code:

if(sw==1)
{ // I assume this is needed
while(sw==1);
pulse++;
}

is executed only once when the program starts. Therefore 'pulse' (which is misspelt in the global declaration by the way) can only ever be 0 (if 'RD0' is 0) or 1 (if RD0 is 1) [BTW - bonus points for trying to debounce this input, even if this doesn't work].
Therefore the following check for 'pulse' to be greater than 500 will always be false.

The next statement uses a different name(rd0_bit) to again check RD0 but the chances of it being clear by the end of the previous 'if' and being set 2 statements later is nearly zero (it just might if the contact bounce is 'just right').

The statement 'pulse = pulse ( *25/60);' will always set 'pulse' to 0. The '25/60' will be performed as integer division which results in 0. Therefore 'pulse' is being multiplied by 0 with makes it 0 as well.

There are many other logical errors but I suspect we are not seeing the real code and so it is pointless going on until we do.

Susan
 
C:
int puls=0;
#define sw portd.rd0
void main(){
trisc=0x00;
portc=0;
trisd.f0=1;
while(1){
if(sw==1)
while(sw==1);
pulse++;
}
if(pulse>=500)pulse=0;
if(rd0_bit==1)pulse++;
if(pulse==pulse<=51){
portc.f4=0;
}
while(1){
if(pulse>=52){
while(pulse==52);
pulse=pulse *(52/60);
pulse=0.8666667;
}
if(pulse>=0.8666667&&pulse<=125){
portc.f4=1;
}

yes that is it
iwant say if i chan

ge​

from////pulse=pulse*(52/60) to pulse *= 52; pulse /= 60; /​

e
help me which is wrong t





=========================
[MODERATOR ACTION]
Added SYNTAX and QUOTE tags
=========================
 
Last edited by a moderator:

You were already warned to post codes appropriatelly formatted.
And, what about being a little carefull and elaborate the question giving more details, aswell checking punctuation and graphy errors ?

Anyway, from the above post, how can one guess the error message that compiler is actually issuing ?
 
Look at the math result from "pulse=pulse *(52/60);"

52 divided by 60 = 0.86666 so stored as an integer it will always be zero. Integers are whole numbers with no fractional part. The smallest positive integer is 1, the smallest negative integer is -1. Zero is zero always.
So:
52 * 0 = 0
774637 * 0 = 0
pulse * 0 = 0
any number * 0 = 0

If you really want to use fractional numbers you must store them as type 'float' or alternatively scale them up so the fractional part can be represented as a whole number. For example instead of 1.23 you scale it by 100 to make it 123.

There are other errors such as "if(pulse==pulse<=51)" which reads as "if the value of pulse is equal to the value of pulse is less than or equal to 51" which doesn't make much sense. It could be interpreted as:
if((pulse == pulse) <= 51); which will always return 1 because (pulse == pulse) will always return true because 1 is less than 51
-or-
it could be interpreted as if(pulse == (pulse<=51)) which will assign the value of 1 or 0 to pulse depending on whether it started off as 52 or more then return true or false.

Brian.
 
hi, if ihave 52 pulse hz need to say v=w/t which t is time taken 60 second ,w=52 one revolution ned value of v simple ineed the v to make action t hanks.
 

if(pulse>=0 &&pulse<=51)
 

It needs double braces:
if((pulse >= 0) && (pulse <= 51))
each part between ( and ) has to evaluate to true or false.
It then checks if each of the two inner braces are both true.

Brian.
 
Lack of ode tags
============================
Moderator action: Added C code tags
============================

C:
float pulse;
#define sw portd.rd0
void main(){
trisc=0x00;
portc=0;
trisd.f0=1;
while(1){
if(sw==1)
while(sw==1);
pulse++;
}
if(pulse>=500)pulse=0;
if(rd0_bit==1)pulse++;
if((pulse>=0)&&(pulse<=51)){
portc.f4=0;
}
while(1){
if(pulse>=52){
while(pulse==52);
pulse=pulse *(52/60);
pulse=0.8666667;
}
if(pulse>=0.8666667&&pulse<=125){
portc.f4=1;
}[syntax=c][/syntax]
 
Last edited by a moderator:

Cannot polish a turd, but I have re-published above code with better formatting and comments as I see it

Maybe OP will spot the errors in his/her own code once the code is more readable?

C:
// random code found on forum - do not blame me, I did not write it!

// need an explanation of what the heck this code is for
// formatting improved and commenting added

float pulse;                                           //

#define sw PORTD.RD0                                   // correct bit name is PORTD.RD0, not portd.rd0 - see datasheet

void main(){
    TRISC = 0x00;                                      // correct register name is TRISC, not trisc - see datasheet
    PORTC = 0;                                         // correct register name is PORTC, not portc - see datasheet
    TRISD.f0 = 1;                                      // correct register name is TRISD, not trisd - see datasheet

    while(1){
        if(sw == 1)                                    // 1 indicates switch pressed
            while(sw == 1);                            // de-bounce missing - wait for switch to be released
        pulse++;                                       // wonder why ?
    }

    // following code will never run due to while loop above
    if(pulse >= 500) pulse = 0;                        // what is special about 500?
    if(sw == 1) pulse++;                               // rd0_bit changed to SW to be consistent
    if((pulse >= 0) && (pulse <= 51)){                 // ?
        PORTC.f4 = 0;                                  // correct register name is TRISC, not trisc - see datasheet
    }
   
    while(1){
        if(pulse >= 52){                               // what is special about 52?
            while(pulse == 52);                        // if exectly 52 found, then hang here and never escape - luckily floats are inexect
            pulse = pulse *(52/60);                    // don't know what was intended - useless anyway as overwritten below
            pulse = 0.8666667;                         // no idea what was intended
        }
        if(pulse >= 0.8666667 && pulse <= 125){        // this is garbage - no idea what was intended
            PORTC.f4 = 1;                              // correct register name is PORTC, not portc - see datasheet
        }
    // missing closing brace
}
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top