cmcon=7; notwork

Fully featured PIC compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

cmcon=7; notwork

#1 Post by adu@love » 17 Nov 2022 05:44

//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
}
}

sgssn
Posts: 35
Joined: 13 Sep 2021 16:24

Re: cmcon=7; notwork

#2 Post by sgssn » 17 Nov 2022 08:56

Hello
it could be helpful, if we would know which PIC you are using. :-)
Gerhard

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: cmcon=7; notwork

#3 Post by hexreader » 17 Nov 2022 11:16

PIC16F877 has no analogue comparator

Simply delete that line of code

... then re-write the Timer 0 code ...

PIC877 Timer 0 works differently to whichever PIC the code was originally written for.

I highly recommend using the correct PIC for the code. Porting to PIC16F877 may be a lot of work, or perhaps even impossible.
Start every day with a smile...... (get it over with) :)

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re: cmcon=7; notwork

#4 Post by adu@love » 18 Nov 2022 09:00

hi thank you when delete cmcon compile ilove you all :D :D

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re: cmcon=7; notwork

#5 Post by adu@love » 19 Nov 2022 08:20

"a=a *(52/60);" if i scale this up mean avoid fraction 0.8666667 *1000000 say j=a; a=8666667;
a=a*(52/60)*1000000;
a=8666667;
j=a;
if(a>=52&& a<100&&j>=8666667){
portc.f1=1;
tel me which is correct
thanks

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re:math operation

#6 Post by adu@love » 20 Nov 2022 11:44

"a=a *(52/60);" if i scale this up mean avoid fraction 0.8666667 *1000000 say j=a; a=8666667;
a=a*(52/60)*1000000;
a=8666667;
j=a;
if(a>=52&& a<100&&j>=8666667){
portc.f1=1;
or :roll: if ido it like this a=a*52;a/60;
a>=0.8666667
tel me which is correct
thanks

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re: cmcon=7; notwork

#7 Post by adu@love » 23 Nov 2022 12:15

/

Re:math operation

#6 Post by adu@love » 20 Nov 2022 02:44
"a=a *(52/60);" if i scale this up mean avoid fraction 0.8666667 *1000000 say j=a; a=8666667;
a=a*(52/60)*1000000;
a=8666667;
j=a;
if(a>=52&& a<100&&j>=8666667){
portc.f1=1;
or :roll: if ido it like this a=a*52;a/60;
a>=0.8666667
tel me which is correct
thanks

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re:correct to be compile

#8 Post by adu@love » 27 Dec 2022 13:05

struct point{
intx;
inty;
};
void point(struct point pt);
void read (struct point *ptr);
void tringle(struct point *ptr);
/*struct point{
intx;
inty;
}; */


int main (void){
struct point tringle [3];
int i;
for (i=0;i<3;i++){
read ( & tringle );
}
tringle(tringle);


return(0);
}
void read (struct point *ptr){
PORTD=ptr;
PORTC=0X00;
PORTC=0;
PORTD=0XFF;
PORTD=0;
PORTC=(" x -coordinate: ");
PORTD = &ptr->x ;
PORTC=(y-coodinate: );
PORTD=(&ptr->y);
}
void print trinGle(struct point * ptr)
{
int i;
for(i=0;i<3;i++){
print point(ptr;
}
void print point(struct point pt){
PORTC=pt.x,pt.y;
}

Post Reply

Return to “PIC AI compilers”