//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
}
}
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;
}
t hank you very muct hThat 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.
thanksThat 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.
thanksThat 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.
pulse=pulse *(25/60);
pulse *= 25; pulse /= 60;
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;
}
ege
from////pulse=pulse*(52/60) to pulse *= 52; pulse /= 60; /
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]
// 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
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?