If you see the files that you can't upload then you have to compress the files to *.zip.when i try to upload i see only hex files not my mikroc file nor the proteus that is why i sent text file of my code
main button RC0 is the start button ? same cycle means previous cycle based on rotary switch position has to run until button connected to RB0 is pressed ?dont select any other cycle and press start button same cycle should continue.
Blower power cannot be controlled using a TRIAC ?
RC0 is connected to a main button ? Main button is a tact switch or Rocker/Slide switch ?
All PORTD pins and RC4 to RC7 connect to 12 position rotart switch ?
Rotary switch should be enabled only when RC0 is low ?
When a rotary switch position is selected after pressing main switch then same cycle has to continue ?
main button RC0 is the start button ? same cycle means previous cycle based on rotary switch position has to run until button connected to RB0 is pressed ?
Edit:
Sorry, main / start button is RC2 ?
Does PORTC.RC3 = 1 work in mikroC PRO PIC Compiler ? I have never tried it like that. I always use PORTC.F3 or PORTC.B3.
The ULN2803 has internal diodes so that's OK.Do you have a diode across the 12v Solenoid?
Thank you for the input, i will certainly keep that in mind next time before selecting a pic. Since i have already made the PCB i would try to rectify this as for now.The ULN2803 has internal diodes so that's OK.
If its true (as I read the original post) that the program works OK when things are quiet then fail when the solenoid is attached I would highly suspect r-m-w issues on PORTC. Seen that, been there.
Any reason to use the '877? Its kind of dog these days. Several 18F's will drop right in and eliminate r-m-w when you use the LATx registers. Take a look at the 4520.
The enhanced midrange parts (16F1xxx) are pretty good, too - at least in C. They have LATx registers for the IO so no r-m-w. They ALSO have the -ME2 debuggers which are fantastic things. 16F1787 et al drops right in.
Tying MCLR to Vdd temporarily will see if MCLR is a problem. The 10K series resistor could be an issue there.
The decoupling on the PIC is a little light.
I've seen this very IO issue many times. I won't use midrange at all any more and that's a big reason.
Good luck.
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;
sbit SOLENOID at RC3_bit;
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define INPUT 1
#define OUTPUT 0
#define SET 1
#define CLEAR 0
char myFlags = 0;
char msg[20];
unsigned int onTimeInMilliSec = 0, offTimeInMilliSec = 0, milliSecCounter = 0;
const char msg1[] = "Select BPM rate";
const char msg2[] = "8 BPM";
const char msg3[] = "10 BPM";
const char msg4[] = "12 BPM";
const char msg5[] = "14 BPM";
const char msg6[] = "16 BPM";
const char msg7[] = "18 BPM";
const char msg8[] = "20 BPM";
const char msg9[] = "24 BPM";
const char msg10[] = "28 BPM";
const char msg11[] = "32 BPM";
const char msg12[] = "36 BPM";
const char msg13[] = "40 BPM";
const char msg14[] = "Stopped";
sbit runFlag at myFlags.B0;
sbit resetFlag at myFlags.B1;
sbit solenoidControlFlag at myFlags.B2;
sbit toggleOnTimeOffTime at myFlags.B3;
sbit runOnceFlag at myFlags.B4;
//Timer1
//Prescaler 1:1; TMR1 Preload = 64536; Actual Interrupt Time : 1 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xFC;
TMR1L = 0x18;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void interrupt() {
if(INTF_bit) {
PORTC.F3 = 0;
runFlag = CLEAR;
resetFlag = TRUE;
TMR1ON_bit = 0;
INTF_bit = CLEAR;
}
if(TMR1IF_bit) {
TMR1H = 0xFC;
TMR1L = 0x18;
if(runFlag) {
++milliSecCounter;
if(toggleOnTimeOffTime) {
if(milliSecCounter == onTimeInMilliSec) {
SOLENOID = OFF;
milliSecCounter = 0;
toggleOnTimeOffTime = 0;
}
}
else if(!toggleOnTimeOffTime) {
if(milliSecCounter == offTimeInMilliSec) {
SOLENOID = ON;
milliSecCounter = 0;
toggleOnTimeOffTime = 1;
}
}
}
TMR1IF_bit = 0;
}
}
//copy const to ram string
char *CopyConst2Ram(char *dest, const char *src) {
char *d;
d = dest;
for(;*dest++ = *src++;);
return d;
}
void main() {
CMCON = 0x07;
CVRCON = 0x00;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0x01;
TRISC = 0xF4;
TRISD = 0xFF;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LCD_Init();
Delay_ms(200);
LCD_cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg1));
INTEDG_bit = 1;
runOnceFlag = 1;
while(1) {
if(!PORTC.F2) {
Delay_ms(50);
while(!PORTC.F2);
runOnceFlag = TRUE;
if(!PORTD.F0) {
Delay_ms(50);
if(!PORTD.F0) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg2));
runFlag = TRUE;
onTimeInMilliSec = 2500;
offTimeInMilliSec = 5000;
}
}
}
else if(!PORTD.F1) {
Delay_ms(50);
if(!PORTD.F1) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg3));
runFlag = TRUE;
onTimeInMilliSec = 2000;
offTimeInMilliSec = 4000;
}
}
}
else if(!PORTD.F2) {
Delay_ms(50);
if(!PORTD.F2) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg4));
runFlag = TRUE;
onTimeInMilliSec = 1670;
offTimeInMilliSec = 3330;
}
}
}
else if(!PORTD.F3) {
Delay_ms(50);
if(!PORTD.F3) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg5));
runFlag = TRUE;
onTimeInMilliSec = 1430;
offTimeInMilliSec = 2850;
}
}
}
else if(!PORTC.F4) {
Delay_ms(50);
if(!PORTC.F4) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg6));
runFlag = TRUE;
onTimeInMilliSec = 1250;
offTimeInMilliSec = 2500;
}
}
}
else if(!PORTC.F5) {
Delay_ms(50);
if(!PORTC.F5) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg7));
runFlag = TRUE;
onTimeInMilliSec = 1110;
offTimeInMilliSec = 2220;
}
}
}
else if(!PORTC.F6) {
Delay_ms(50);
if(!PORTC.F6) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg8));
runFlag = TRUE;
onTimeInMilliSec = 1000;
offTimeInMilliSec = 2000;
}
}
}
else if(!PORTC.F7) {
Delay_ms(50);
if(!PORTC.F7) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg9));
runFlag = TRUE;
onTimeInMilliSec = 830;
offTimeInMilliSec = 1660;
}
}
}
else if(!PORTD.F4) {
Delay_ms(50);
if(!PORTD.F4) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg10));
runFlag = TRUE;
onTimeInMilliSec = 720;
offTimeInMilliSec = 1440;
}
}
}
else if(!PORTD.F5) {
Delay_ms(50);
if(!PORTD.F5) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg11));
runFlag = TRUE;
onTimeInMilliSec = 630;
offTimeInMilliSec = 1260;
}
}
}
else if(!PORTD.F6) {
Delay_ms(50);
if(!PORTD.F6) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg12));
runFlag = TRUE;
onTimeInMilliSec = 560;
offTimeInMilliSec = 1120; ;
}
}
}
else if(!PORTD.F7) {
Delay_ms(50);
if(!PORTD.F7) {
if(runOnceFlag) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg13));
runFlag = TRUE;
onTimeInMilliSec = 500;
offTimeInMilliSec = 1000;
}
}
}
if(runOnceFlag) {
toggleOnTimeOffTime = 1;
SOLENOID = ON;
InitTimer1();
runOnceFlag = CLEAR;
}
}
if(resetFlag == TRUE) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg14));
resetFlag = CLEAR;
}
}
}
OK.. do note that the chips I called out drop into the same socket. MikroC has pretty good support for both families.Thank you for the input, i will certainly keep that in mind next time before selecting a pic. Since i have already made the PCB i would try to rectify this as for now.
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;
sbit SOLENOID at RC3_bit;
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define INPUT 1
#define OUTPUT 0
#define SET 1
#define CLEAR 0
char myFlags = 0;
char msg[20];
unsigned int onTimeInMilliSec = 0, offTimeInMilliSec = 0, milliSecCounter = 0;
const char msg1[] = "Select BPM rate";
const char msg2[] = "8 BPM";
const char msg3[] = "10 BPM";
const char msg4[] = "12 BPM";
const char msg5[] = "14 BPM";
const char msg6[] = "16 BPM";
const char msg7[] = "18 BPM";
const char msg8[] = "20 BPM";
const char msg9[] = "24 BPM";
const char msg10[] = "28 BPM";
const char msg11[] = "32 BPM";
const char msg12[] = "36 BPM";
const char msg13[] = "40 BPM";
const char msg14[] = "Stopped";
sbit runFlag at myFlags.B0;
sbit resetFlag at myFlags.B1;
sbit solenoidControlFlag at myFlags.B2;
sbit toggleOnTimeOffTime at myFlags.B3;
sbit runOnceFlag at myFlags.B4;
//Timer1
//Prescaler 1:1; TMR1 Preload = 64536; Actual Interrupt Time : 1 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xFC;
TMR1L = 0x18;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void interrupt() {
if(INTF_bit) {
PORTC.F3 = 0;
runFlag = CLEAR;
resetFlag = TRUE;
TMR1ON_bit = 0;
INTF_bit = CLEAR;
}
if(TMR1IF_bit) {
TMR1H = 0xFC;
TMR1L = 0x18;
if(runFlag) {
++milliSecCounter;
if(toggleOnTimeOffTime) {
if(milliSecCounter == onTimeInMilliSec) {
SOLENOID = OFF;
milliSecCounter = 0;
toggleOnTimeOffTime = 0;
}
}
else if(!toggleOnTimeOffTime) {
if(milliSecCounter == offTimeInMilliSec) {
SOLENOID = ON;
milliSecCounter = 0;
toggleOnTimeOffTime = 1;
}
}
}
TMR1IF_bit = 0;
}
}
//copy const to ram string
char *CopyConst2Ram(char *dest, const char *src) {
char *d;
d = dest;
for(;*dest++ = *src++;);
return d;
}
void main() {
CMCON = 0x07;
CVRCON = 0x00;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0x01;
TRISC = 0xF4;
TRISD = 0xFF;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LCD_Init();
Delay_ms(200);
LCD_cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg1));
INTEDG_bit = 1;
runOnceFlag = 1;
while(1) {
if(!PORTC.F2) {
Delay_ms(50);
while(!PORTC.F2);
runOnceFlag = TRUE;
LCD_Cmd(_LCD_CLEAR);
if(!PORTD.F0) {
Delay_ms(50);
if(!PORTD.F0) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg2));
runFlag = TRUE;
onTimeInMilliSec = 2500;
offTimeInMilliSec = 5000;
}
}
}
else if(!PORTD.F1) {
Delay_ms(50);
if(!PORTD.F1) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg3));
runFlag = TRUE;
onTimeInMilliSec = 2000;
offTimeInMilliSec = 4000;
}
}
}
else if(!PORTD.F2) {
Delay_ms(50);
if(!PORTD.F2) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg4));
runFlag = TRUE;
onTimeInMilliSec = 1670;
offTimeInMilliSec = 3330;
}
}
}
else if(!PORTD.F3) {
Delay_ms(50);
if(!PORTD.F3) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg5));
runFlag = TRUE;
onTimeInMilliSec = 1430;
offTimeInMilliSec = 2850;
}
}
}
else if(!PORTC.F4) {
Delay_ms(50);
if(!PORTC.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg6));
runFlag = TRUE;
onTimeInMilliSec = 1250;
offTimeInMilliSec = 2500;
}
}
}
else if(!PORTC.F5) {
Delay_ms(50);
if(!PORTC.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg7));
runFlag = TRUE;
onTimeInMilliSec = 1110;
offTimeInMilliSec = 2220;
}
}
}
else if(!PORTC.F6) {
Delay_ms(50);
if(!PORTC.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg8));
runFlag = TRUE;
onTimeInMilliSec = 1000;
offTimeInMilliSec = 2000;
}
}
}
else if(!PORTC.F7) {
Delay_ms(50);
if(!PORTC.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg9));
runFlag = TRUE;
onTimeInMilliSec = 830;
offTimeInMilliSec = 1660;
}
}
}
else if(!PORTD.F4) {
Delay_ms(50);
if(!PORTD.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg10));
runFlag = TRUE;
onTimeInMilliSec = 720;
offTimeInMilliSec = 1440;
}
}
}
else if(!PORTD.F5) {
Delay_ms(50);
if(!PORTD.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg11));
runFlag = TRUE;
onTimeInMilliSec = 630;
offTimeInMilliSec = 1260;
}
}
}
else if(!PORTD.F6) {
Delay_ms(50);
if(!PORTD.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg12));
runFlag = TRUE;
onTimeInMilliSec = 560;
offTimeInMilliSec = 1120; ;
}
}
}
else if(!PORTD.F7) {
Delay_ms(50);
if(!PORTD.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg13));
runFlag = TRUE;
onTimeInMilliSec = 500;
offTimeInMilliSec = 1000;
}
}
}
if(runOnceFlag) {
toggleOnTimeOffTime = 1;
SOLENOID = ON;
InitTimer1();
runOnceFlag = CLEAR;
}
}
if(resetFlag == TRUE) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg14));
resetFlag = CLEAR;
}
}
}
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;
sbit SOLENOID at RC3_bit;
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define INPUT 1
#define OUTPUT 0
#define SET 1
#define CLEAR 0
char myFlags = 0;
char msg[20];
unsigned int onTimeInMilliSec = 0, offTimeInMilliSec = 0, milliSecCounter = 0;
const char msg1[] = "Select BPM rate";
const char msg2[] = "8 BPM";
const char msg3[] = "10 BPM";
const char msg4[] = "12 BPM";
const char msg5[] = "14 BPM";
const char msg6[] = "16 BPM";
const char msg7[] = "18 BPM";
const char msg8[] = "20 BPM";
const char msg9[] = "24 BPM";
const char msg10[] = "28 BPM";
const char msg11[] = "32 BPM";
const char msg12[] = "36 BPM";
const char msg13[] = "40 BPM";
const char msg14[] = "Stopped";
sbit runFlag at myFlags.B0;
sbit resetFlag at myFlags.B1;
sbit solenoidControlFlag at myFlags.B2;
sbit toggleOnTimeOffTime at myFlags.B3;
sbit runOnceFlag at myFlags.B4;
//Timer1
//Prescaler 1:1; TMR1 Preload = 15536; Actual Interrupt Time : 10 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void interrupt() {
if(INTF_bit) {
PORTC.F3 = 0;
runFlag = CLEAR;
resetFlag = TRUE;
TMR1ON_bit = 0;
INTF_bit = CLEAR;
}
if(TMR1IF_bit) {
TMR1H = 0xFC;
TMR1L = 0x18;
if(runFlag) {
++milliSecCounter;
if(toggleOnTimeOffTime) {
if(milliSecCounter == onTimeInMilliSec) {
SOLENOID = OFF;
milliSecCounter = 0;
toggleOnTimeOffTime = 0;
}
}
else if(!toggleOnTimeOffTime) {
if(milliSecCounter == offTimeInMilliSec) {
SOLENOID = ON;
milliSecCounter = 0;
toggleOnTimeOffTime = 1;
}
}
}
TMR1IF_bit = 0;
}
}
//copy const to ram string
char *CopyConst2Ram(char *dest, const char *src) {
char *d;
d = dest;
for(;*dest++ = *src++;);
return d;
}
void main() {
CMCON = 0x07;
CVRCON = 0x00;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0x01;
TRISC = 0xF4;
TRISD = 0xFF;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LCD_Init();
Delay_ms(200);
LCD_cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg1));
INTEDG_bit = 1;
runOnceFlag = 1;
while(1) {
if(!PORTC.F2) {
Delay_ms(50);
while(!PORTC.F2);
runOnceFlag = TRUE;
LCD_Cmd(_LCD_CLEAR);
if(!PORTD.F0) {
Delay_ms(50);
if(!PORTD.F0) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg2));
runFlag = TRUE;
onTimeInMilliSec = 250;
offTimeInMilliSec = 500;
}
}
}
else if(!PORTD.F1) {
Delay_ms(50);
if(!PORTD.F1) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg3));
runFlag = TRUE;
onTimeInMilliSec = 200;
offTimeInMilliSec = 400;
}
}
}
else if(!PORTD.F2) {
Delay_ms(50);
if(!PORTD.F2) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg4));
runFlag = TRUE;
onTimeInMilliSec = 167;
offTimeInMilliSec = 333;
}
}
}
else if(!PORTD.F3) {
Delay_ms(50);
if(!PORTD.F3) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg5));
runFlag = TRUE;
onTimeInMilliSec = 143;
offTimeInMilliSec = 285;
}
}
}
else if(!PORTC.F4) {
Delay_ms(50);
if(!PORTC.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg6));
runFlag = TRUE;
onTimeInMilliSec = 125;
offTimeInMilliSec = 250;
}
}
}
else if(!PORTC.F5) {
Delay_ms(50);
if(!PORTC.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg7));
runFlag = TRUE;
onTimeInMilliSec = 111;
offTimeInMilliSec = 222;
}
}
}
else if(!PORTC.F6) {
Delay_ms(50);
if(!PORTC.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg8));
runFlag = TRUE;
onTimeInMilliSec = 100;
offTimeInMilliSec = 200;
}
}
}
else if(!PORTC.F7) {
Delay_ms(50);
if(!PORTC.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg9));
runFlag = TRUE;
onTimeInMilliSec = 83;
offTimeInMilliSec = 166;
}
}
}
else if(!PORTD.F4) {
Delay_ms(50);
if(!PORTD.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg10));
runFlag = TRUE;
onTimeInMilliSec = 72;
offTimeInMilliSec = 144;
}
}
}
else if(!PORTD.F5) {
Delay_ms(50);
if(!PORTD.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg11));
runFlag = TRUE;
onTimeInMilliSec = 63;
offTimeInMilliSec = 126;
}
}
}
else if(!PORTD.F6) {
Delay_ms(50);
if(!PORTD.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg12));
runFlag = TRUE;
onTimeInMilliSec = 56;
offTimeInMilliSec = 112; ;
}
}
}
else if(!PORTD.F7) {
Delay_ms(50);
if(!PORTD.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg13));
runFlag = TRUE;
onTimeInMilliSec = 50;
offTimeInMilliSec = 100;
}
}
}
if(runOnceFlag) {
toggleOnTimeOffTime = 1;
SOLENOID = ON;
InitTimer1();
runOnceFlag = CLEAR;
}
}
if(resetFlag == TRUE) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg14));
resetFlag = CLEAR;
}
}
}
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;
sbit SOLENOID at RC3_bit;
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define INPUT 1
#define OUTPUT 0
#define SET 1
#define CLEAR 0
char myFlags = 0;
char msg[20];
unsigned int onTimeInMilliSec = 0, offTimeInMilliSec = 0, milliSecCounter = 0;
const char msg1[] = "Select BPM rate";
const char msg2[] = "8 BPM";
const char msg3[] = "10 BPM";
const char msg4[] = "12 BPM";
const char msg5[] = "14 BPM";
const char msg6[] = "16 BPM";
const char msg7[] = "18 BPM";
const char msg8[] = "20 BPM";
const char msg9[] = "24 BPM";
const char msg10[] = "28 BPM";
const char msg11[] = "32 BPM";
const char msg12[] = "36 BPM";
const char msg13[] = "40 BPM";
const char msg14[] = "Stopped";
sbit runFlag at myFlags.B0;
sbit resetFlag at myFlags.B1;
sbit solenoidControlFlag at myFlags.B2;
sbit toggleOnTimeOffTime at myFlags.B3;
sbit runOnceFlag at myFlags.B4;
//Timer1
//Prescaler 1:1; TMR1 Preload = 15536; Actual Interrupt Time : 10 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void interrupt() {
if(INTF_bit) {
PORTC.F3 = 0;
runFlag = CLEAR;
resetFlag = TRUE;
TMR1ON_bit = 0;
INTE_bit = 0;
INTF_bit = CLEAR;
}
if(TMR1IF_bit) {
TMR1H = 0xFC;
TMR1L = 0x18;
if(runFlag) {
++milliSecCounter;
if(toggleOnTimeOffTime) {
if(milliSecCounter == onTimeInMilliSec) {
SOLENOID = OFF;
milliSecCounter = 0;
toggleOnTimeOffTime = 0;
}
}
else if(!toggleOnTimeOffTime) {
if(milliSecCounter == offTimeInMilliSec) {
SOLENOID = ON;
milliSecCounter = 0;
toggleOnTimeOffTime = 1;
}
}
}
TMR1IF_bit = 0;
}
}
//copy const to ram string
char *CopyConst2Ram(char *dest, const char *src) {
char *d;
d = dest;
for(;*dest++ = *src++;);
return d;
}
void main() {
CMCON = 0x07;
CVRCON = 0x00;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0x01;
TRISC = 0xF4;
TRISD = 0xFF;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LCD_Init();
Delay_ms(200);
LCD_cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg1));
INTEDG_bit = 1;
runOnceFlag = 1;
while(1) {
if(!PORTC.F2) {
Delay_ms(50);
while(!PORTC.F2);
runOnceFlag = TRUE;
LCD_Cmd(_LCD_CLEAR);
if(!PORTD.F0) {
Delay_ms(50);
if(!PORTD.F0) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg2));
runFlag = TRUE;
onTimeInMilliSec = 250;
offTimeInMilliSec = 500;
}
}
}
else if(!PORTD.F1) {
Delay_ms(50);
if(!PORTD.F1) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg3));
runFlag = TRUE;
onTimeInMilliSec = 200;
offTimeInMilliSec = 400;
}
}
}
else if(!PORTD.F2) {
Delay_ms(50);
if(!PORTD.F2) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg4));
runFlag = TRUE;
onTimeInMilliSec = 167;
offTimeInMilliSec = 333;
}
}
}
else if(!PORTD.F3) {
Delay_ms(50);
if(!PORTD.F3) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg5));
runFlag = TRUE;
onTimeInMilliSec = 143;
offTimeInMilliSec = 285;
}
}
}
else if(!PORTC.F4) {
Delay_ms(50);
if(!PORTC.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg6));
runFlag = TRUE;
onTimeInMilliSec = 125;
offTimeInMilliSec = 250;
}
}
}
else if(!PORTC.F5) {
Delay_ms(50);
if(!PORTC.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg7));
runFlag = TRUE;
onTimeInMilliSec = 111;
offTimeInMilliSec = 222;
}
}
}
else if(!PORTC.F6) {
Delay_ms(50);
if(!PORTC.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg8));
runFlag = TRUE;
onTimeInMilliSec = 100;
offTimeInMilliSec = 200;
}
}
}
else if(!PORTC.F7) {
Delay_ms(50);
if(!PORTC.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg9));
runFlag = TRUE;
onTimeInMilliSec = 83;
offTimeInMilliSec = 166;
}
}
}
else if(!PORTD.F4) {
Delay_ms(50);
if(!PORTD.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg10));
runFlag = TRUE;
onTimeInMilliSec = 72;
offTimeInMilliSec = 144;
}
}
}
else if(!PORTD.F5) {
Delay_ms(50);
if(!PORTD.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg11));
runFlag = TRUE;
onTimeInMilliSec = 63;
offTimeInMilliSec = 126;
}
}
}
else if(!PORTD.F6) {
Delay_ms(50);
if(!PORTD.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg12));
runFlag = TRUE;
onTimeInMilliSec = 56;
offTimeInMilliSec = 112; ;
}
}
}
else if(!PORTD.F7) {
Delay_ms(50);
if(!PORTD.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg13));
runFlag = TRUE;
onTimeInMilliSec = 50;
offTimeInMilliSec = 100;
}
}
}
if(runOnceFlag) {
toggleOnTimeOffTime = 1;
SOLENOID = ON;
INTF_bit = 0;
INTE_bit = 1;
InitTimer1();
runOnceFlag = CLEAR;
}
}
if(resetFlag == TRUE) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg14));
resetFlag = CLEAR;
}
}
}
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;
sbit SOLENOID at RC3_bit;
sbit LED1 at RA0_bit;
sbit LED2 at RA1_bit;
sbit LED3 at RA2_bit;
sbit LED4 at RA3_bit;
sbit LED5 at RB7_bit;
sbit LED6 at RA5_bit;
sbit LED7 at RE0_bit;
sbit LED8 at RE1_bit;
sbit LED9 at RE2_bit;
sbit LED10 at RC0_bit;
sbit LED11 at RC1_bit;
sbit LED12 at RC2_bit;
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define INPUT 1
#define OUTPUT 0
#define SET 1
#define CLEAR 0
#define ENABLE 1
#define DISABLE 0
char myFlags = 0, startStopCounter = 0;
char msg[20];
unsigned int onTimeInMilliSec = 0, offTimeInMilliSec = 0, milliSecCounter = 0;
const char msg1[] = "Select BPM rate";
const char msg2[] = "8 BPM";
const char msg3[] = "10 BPM";
const char msg4[] = "12 BPM";
const char msg5[] = "14 BPM";
const char msg6[] = "16 BPM";
const char msg7[] = "18 BPM";
const char msg8[] = "20 BPM";
const char msg9[] = "24 BPM";
const char msg10[] = "28 BPM";
const char msg11[] = "32 BPM";
const char msg12[] = "36 BPM";
const char msg13[] = "40 BPM";
const char msg14[] = "Stopped";
sbit runFlag at myFlags.B0;
sbit resetFlag at myFlags.B1;
sbit solenoidControlFlag at myFlags.B2;
sbit toggleOnTimeOffTime at myFlags.B3;
sbit runOnceFlag at myFlags.B4;
//Timer1
//Prescaler 1:1; TMR1 Preload = 15536; Actual Interrupt Time : 10 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void interrupt() {
if(INTF_bit) {
startStopCounter++;
INTE_bit = ENABLE;
INTF_bit = CLEAR;
if(startStopCounter == 3) {
resetFlag = TRUE;
}
}
if(TMR1IF_bit) {
TMR1H = 0xFC;
TMR1L = 0x18;
if(runFlag) {
++milliSecCounter;
if(toggleOnTimeOffTime) {
if(milliSecCounter == onTimeInMilliSec) {
SOLENOID = OFF;
milliSecCounter = 0;
toggleOnTimeOffTime = 0;
}
}
else if(!toggleOnTimeOffTime) {
if(milliSecCounter == offTimeInMilliSec) {
SOLENOID = ON;
milliSecCounter = 0;
toggleOnTimeOffTime = 1;
}
}
}
TMR1IF_bit = 0;
}
}
//copy const to ram string
char *CopyConst2Ram(char *dest, const char *src) {
char *d;
d = dest;
for(;*dest++ = *src++;);
return d;
}
void TurnOffLeds() {
LED1 = OFF;
LED2 = OFF;
LED3 = OFF;
LED4 = OFF;
LED5 = OFF;
LED6 = OFF;
LED7 = OFF;
LED8 = OFF;
LED9 = OFF;
LED10 = OFF;
LED11 = OFF;
LED12 = OFF;
}
void main() {
CMCON = 0x07;
CVRCON = 0x00;
ADCON1 = 0x87;
TRISA = 0x00;
TRISB = 0x01;
TRISC = 0xF0;
TRISD = 0xFF;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LCD_Init();
Delay_ms(200);
LCD_cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg1));
INTEDG_bit = 1;
runOnceFlag = 1;
INTEDG_bit = 1;
INTE_bit = 1;
INTF_bit = 0;
while(1) {
if(startStopCounter == 1) {
runOnceFlag = TRUE;
LCD_Cmd(_LCD_CLEAR);
if(!PORTD.F0) {
Delay_ms(50);
if(!PORTD.F0) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg2));
runFlag = TRUE;
onTimeInMilliSec = 250;
offTimeInMilliSec = 500;
LED1 = ON;
}
}
}
else if(!PORTD.F1) {
Delay_ms(50);
if(!PORTD.F1) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg3));
runFlag = TRUE;
onTimeInMilliSec = 200;
offTimeInMilliSec = 400;
LED2 = ON;
}
}
}
else if(!PORTD.F2) {
Delay_ms(50);
if(!PORTD.F2) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg4));
runFlag = TRUE;
onTimeInMilliSec = 167;
offTimeInMilliSec = 333;
LED3 = ON;
}
}
}
else if(!PORTD.F3) {
Delay_ms(50);
if(!PORTD.F3) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg5));
runFlag = TRUE;
onTimeInMilliSec = 143;
offTimeInMilliSec = 285;
LED4 = ON;
}
}
}
else if(!PORTC.F4) {
Delay_ms(50);
if(!PORTC.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg6));
runFlag = TRUE;
onTimeInMilliSec = 125;
offTimeInMilliSec = 250;
LED5 = ON;
}
}
}
else if(!PORTC.F5) {
Delay_ms(50);
if(!PORTC.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg7));
runFlag = TRUE;
onTimeInMilliSec = 111;
offTimeInMilliSec = 222;
LED6 = ON;
}
}
}
else if(!PORTC.F6) {
Delay_ms(50);
if(!PORTC.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg8));
runFlag = TRUE;
onTimeInMilliSec = 100;
offTimeInMilliSec = 200;
LED7 = ON;
}
}
}
else if(!PORTC.F7) {
Delay_ms(50);
if(!PORTC.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg9));
runFlag = TRUE;
onTimeInMilliSec = 83;
offTimeInMilliSec = 166;
LED8 = ON;
}
}
}
else if(!PORTD.F4) {
Delay_ms(50);
if(!PORTD.F4) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg10));
runFlag = TRUE;
onTimeInMilliSec = 72;
offTimeInMilliSec = 144;
LED9 = ON;
}
}
}
else if(!PORTD.F5) {
Delay_ms(50);
if(!PORTD.F5) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg11));
runFlag = TRUE;
onTimeInMilliSec = 63;
offTimeInMilliSec = 126;
LED10 = ON;
}
}
}
else if(!PORTD.F6) {
Delay_ms(50);
if(!PORTD.F6) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg12));
runFlag = TRUE;
onTimeInMilliSec = 56;
offTimeInMilliSec = 112;
LED11 = ON; ;
}
}
}
else if(!PORTD.F7) {
Delay_ms(50);
if(!PORTD.F7) {
if(runOnceFlag) {
LCD_Out(1,1,CopyConst2Ram(msg, msg13));
runFlag = TRUE;
onTimeInMilliSec = 50;
offTimeInMilliSec = 100;
LED12 = ON;
}
}
}
if(runOnceFlag) {
startStopCounter++;
toggleOnTimeOffTime = 1;
SOLENOID = ON;
INTE_bit = ENABLE;
INTF_bit = 0;
InitTimer1();
runOnceFlag = CLEAR;
}
}
if(resetFlag == TRUE) {
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1,CopyConst2Ram(msg, msg14));
resetFlag = CLEAR;
SOLENOID = OFF;
runFlag = CLEAR;
TMR1ON_bit = 0;
startStopCounter = 0;
TurnOffLeds();
INTE_bit = ENABLE;
INTF_bit = CLEAR;
}
}
}