lindodv
Junior Member level 1
- Joined
- Jul 4, 2014
- Messages
- 16
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 121
I used Mikoc pro for PIC v6.4 software - and I used switch command for increasing size of C code.
if I decrease size of code(by deleting some switch commands ) everything is correct but...I don't know why! :-(
I add simulator-c code- and hex in new folder.
if I decrease size of code(by deleting some switch commands ) everything is correct but...I don't know why! :-(
I add simulator-c code- and hex in new folder.
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
char *texttimer = "00/00:00";
unsigned char *textworktimetimer = "00:00";
unsigned char *timer = "00/00:00:00";
unsigned int i=0,set=0,inter=0;
unsigned short count_m=0,count_h=0,count_d=0;
unsigned int count_twm=0 ,count_twh=0;
unsigned int Count=0 ,count_min=0 ,count_hour=0 ,count_day=0 ;
unsigned short timerON=0;
void setswitch () {
if (PORTA.F0 == 0) { // set push button
delay_ms(10);
if (PORTA.F0 == 0) {
set ++; } }
while (PORTA.F0 == 0);
if (set >= 5) {
set = 0; }
switch(set){ //0-4
case 0:
PORTD = 0b00000001;
break;
case 1:
PORTD = 0b00000010;
switch(inter){ //0-5 taghvim - time
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break; }
break;
case 2: // timer F3=inter push button
if (PORTA.F3 == 0) {
delay_ms(100);
if (PORTA.F3 == 0) {
inter ++; } }
while (PORTA.F3 == 0);
if (inter >=7) {
inter =0; }
switch(inter){ //0-6 timer-counter
case 0:
PORTD = 0b00000001;
Lcd_Out(2,1,"Timer is OFF");
timerON = 0;
break;
case 1: // inter minute
PORTD = 0b00000010;
Lcd_Out(2,1,"SET Timer ");
if (PORTA.F2 == 0) {
delay_ms(100);
if (PORTA.F2 == 0) {
count_m ++; } }
if (PORTA.F1 == 0) {
delay_ms(100);
if (PORTA.F1 == 0) {
count_m --; } }
texttimer[6] = ((count_m/10)%10)+48;
texttimer[7] = ((count_m/1)%10)+48;
delay_us(10000);
Lcd_out(2,18," ");
delay_us(10000);
texttimer[0] = ((count_d/10)%10)+48;
texttimer[1] = ((count_d/1)%10)+48;
texttimer[3] = ((count_h/10)%10)+48;
texttimer[4] = ((count_h/1)%10)+48;
texttimer[6] = ((count_m/10)%10)+48;
texttimer[7] = ((count_m/1)%10)+48;
Lcd_Out(2,12,texttimer);
break;
case 2: // inter hour
PORTD = 0b00000011;
Lcd_Out(2,1,"SET Timer ");
if (PORTA.F2 == 0) {
delay_ms(100);
if (PORTA.F2 == 0) {
count_h ++; } }
if (PORTA.F1 == 0) {
delay_ms(100);
if (PORTA.F1 == 0) {
count_h --; } }
texttimer[3] = ((count_h/10)%10)+48;
texttimer[4] = ((count_h/1)%10)+48;
delay_us(10000);
Lcd_out(2,15," ");
delay_us(10000);;
texttimer[0] = ((count_d/10)%10)+48;
texttimer[1] = ((count_d/1)%10)+48;
texttimer[3] = ((count_h/10)%10)+48;
texttimer[4] = ((count_h/1)%10)+48;
texttimer[6] = ((count_m/10)%10)+48;
texttimer[7] = ((count_m/1)%10)+48;
Lcd_Out(2,12,texttimer);
break;
case 3: // inter day
PORTD = 0b00000100;
Lcd_Out(2,1,"SET Timer ");
if (PORTA.F2 == 0) {
delay_ms(100);
if (PORTA.F2 == 0) {
count_d ++; } }
if (PORTA.F1 == 0) {
delay_ms(100);
if (PORTA.F1 == 0) {
count_d --; } }
texttimer[0] = ((count_d/10)%10)+48;
texttimer[1] = ((count_d/1)%10)+48;
delay_us(10000);
Lcd_out(2,12," ");
delay_us(10000);
texttimer[0] = ((count_d/10)%10)+48;
texttimer[1] = ((count_d/1)%10)+48;
texttimer[3] = ((count_h/10)%10)+48;
texttimer[4] = ((count_h/1)%10)+48;
texttimer[6] = ((count_m/10)%10)+48;
texttimer[7] = ((count_m/1)%10)+48;
Lcd_Out(2,12,texttimer);
break;
case 4: // inter minute for work time
PORTD = 0b00000101;
Lcd_Out(2,1,"SET Work Time ");
if (PORTA.F2 == 0) {
delay_ms(100);
if (PORTA.F2 == 0) {
count_twm ++; } }
if (PORTA.F1 == 0) {
delay_ms(100);
if (PORTA.F1 == 0) {
count_twm --; } }
textworktimetimer[3] = ((count_twm/10)%10)+48;
textworktimetimer[4] = ((count_twm/1)%10)+48;
delay_ms(50);
Lcd_out(2,18," ");
delay_ms(50);
textworktimetimer[0] = ((count_twh/10)%10)+48;
textworktimetimer[1] = ((count_twh/1)%10)+48;
textworktimetimer[3] = ((count_twm/10)%10)+48;
textworktimetimer[4] = ((count_twm/1)%10)+48;
Lcd_Out(2,15,textworktimetimer);
break;
case 6:
Lcd_Out(2,1,"Timer is ON ");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
timerON = 1;
set =0;
break; }
break;
case 3:
PORTD = 0b00001000;
switch(inter){ //0-3
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break; }
break;
case 4:
PORTD = 0b00010000;
switch(inter){ //0-3
case 0:
Lcd_Out(2,1,"SET Work Time ");
if (PORTA.F2 == 0) {
delay_ms(100);
if (PORTA.F2 == 0) {
count_twh ++; } }
if (PORTA.F1 == 0) {
delay_ms(100);
if (PORTA.F1 == 0) {
count_twh --; } }
textworktimetimer[0] = ((count_twh/10)%10)+48;
textworktimetimer[1] = ((count_twh/1)%10)+48;
delay_ms(150);
Lcd_out(2,15," ");
delay_ms(150);
textworktimetimer[0] = ((count_twh/10)%10)+48;
textworktimetimer[1] = ((count_twh/1)%10)+48;
textworktimetimer[3] = ((count_twm/10)%10)+48;
textworktimetimer[4] = ((count_twm/1)%10)+48;
Lcd_Out(2,15,textworktimetimer);
break;
case 1:
break;
case 2:
break;
case 3:
break; }
break; }
}
void main() {
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
OPTION_REG = 0b00000111; //RBPU=0 INTEDG=0 T0CS=0(internal) T0SE=0(Reaction on low2high) PSA=0(work with prescaler) PS2,PS1,PS0=111(1:256)
TRISA = 0xFF;
ADCON1 = 0x07;
CMCON = 0x07;
TRISD = 0;
PORTD = 0;
timerON =0;
while (1)
{
if (timerON==1) {
setswitch ();
}
if (timerON==0) {
while (! TMR0);
TMR0 = 0;
Count ++;
timer[0] = ((Count/100000000)%10)+48;
timer[1] = ((Count/10000000)%10)+48;
timer[3] = ((Count/1000000)%10)+48;
timer[4] = ((Count/100000)%10)+48;
timer[6] = ((Count/10000)%10)+48;
timer[7] = ((Count/1000)%10)+48;
timer[9] = ((Count/100)%10)+48;
timer[10] = ((Count/10)%10)+48;
Lcd_Out(2, 1,"timer");
Lcd_Out(2, 10,timer);
}
}
}