kanai42
Newbie level 6
- Joined
- Apr 18, 2013
- Messages
- 12
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,353
I have wrote this program for that circuit with intention of counting every pulse that comes out of the signal generator but its not working so please check the project files in the attachment.
**broken link removed**
Code:
// Lcd pinout settings
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;
char* message1 = "Welcome";
char* message2 = "Kanatronix Labs.";
char* sCPM = "000000";
char* sCPS = "000000";
unsigned long tiks = 0, piks = 0, t1 = 0 , t2 = 0, out = 0, cpm = 0, cps = 0, px = 1;
//Timer1
//Prescaler 1:1; TMR1 Preload = 64536; Actual Interrupt Time : 500 us
//Place/Copy this part in declaration section
void InitTimer1(){
TMR1IE_bit = 1;
TMR1IF_bit = 0;
TMR1H = 0xFC;
TMR1L = 0x18;
T1CON = 0b10001001;
CCP1CON = 0b00000101;
INTCON = 0xC0;
TMR1ON_bit = 1;
CCP1IF_bit = 0;
CCP1IE_bit = 1;
}
void Ports(){
TRISC = 0xFF;
PORTC = 1;
}
void Interrupt(){
if (TMR1IF_bit){
TMR1IF_bit = 0;
//////////////////
tiks++;
}
if (CCP1IF_bit){
piks++;
CCP1IF_bit = 0;
t1 = CCPR1;
tiks = 0;
}
}
void main() {
Ports();
InitTimer1();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,4,message1);
Lcd_Out(2,1,message2);
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(1000);
while(1) {
{
t2 = (65536 * tiks) + CCPR1;
t2 = t2 - t1;
cpm = 120e6 / t2;
cps = cpm / 60;
tiks = 0;
LCD_Out(1,3, "KANAI MONITOR");
LCD_Out(2,1, "CPM");
if(px != cpm) {
LongToStr(cpm, sCPM);
LCD_Out(2,5, " ");
LCD_Out(2,7, sCPM);
px = cpm;
}
t2 = 0;
t1 = 0;
piks = 0;
out = 0;
CCP1IE_bit = 1;
}
}
}