Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 void interrupt() { if(TMR2IF_bit) { TMR2IF_bit = 0; Clock1 = ~Clock1; } } void PORT_Ini(void) { TRISA = 0xFF; // PORTA input TRISB = 0b00000001; // PORTB output except RB0 & RB1 PORTB = 0x00; // all zero TRISC = 0b00001000; // PORTC output PORTC = 0x00; // all zero } void main() { PORT_Ini(void); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Buzzer = 1; Delay_ms(500); Buzzer = 0; Delay_ms(500); ADCON1=0x00; OPTION_REG = 0x00; // Timer settings T2CON = 0b01011101; CCP2CON = 0b00001010; TMR2 = 0; PR2 = 255; GIE_bit = 1; PEIE_bit = 1; //TMR2IE_bit = 1; while(1) { Run_IPS(void); Get_Battery(void); Display_Battery(void); LCD_Parameter(0); } // while }// void main
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 sbit PORT2TOGGLE at RC0_bit; //Timer2 //Prescaler 1:16; Postscaler 1:7; TMR2 Preload = 223; Actual Interrupt Time : 9.9932 ms //Place/Copy this part in declaration section void InitTimer2(){ T2CON = 0x36; PR2 = 223; TMR2IE_bit = 1; INTCON = 0xC0; } void Interrupt(){ if (TMR2IF_bit){ PORT2TOGGLE = ~PORT2TOGGLE; PR2 = 223; TMR2IF_bit = 0; } } void main() { InitTimer2(); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 #define Clock1 RC5_bit void interrupt() { if(CCP1IF_bit) { CCP1IF_bit = 0;// clear flag Clock1 = 0; } if(TMR2IF_bit) { Clock1 = 1; TMR2IF_bit = 0;//clear flag } } // ISR... void PORT_Init(void) { TRISA = 0xFF; // PORTA input TRISB = 0b00000001; // PORTB output except RB0 & RB1 PORTB = 0x00; // all zero TRISC = 0b00001000; // PORTC output PORTC = 0x00; // all zero } void main() { PORT_Init(void); // Timer2 settings for 7ms interrupt T2CON = 0x36; PR2 = 223; // 10 ms time TMR2IE_bit = 1; INTCON = 0xC0; // compare module settings... CCP1CON = 0b00001011;// trigger special event CCP1IE_bit = 1; CCPR1L = 0x1B; CCPR1H = 0xCF; //timer 1 settings... T1CON = 0x01; TMR1IF_bit = 0; TMR1H = 0xCF;//10ms timer TMR1L = 0x2B; while(1) { } // while }// void main
CCPR1H = 0x61;
CCPR1L = 0xA8;
CCPR1H = 0x31;
CCPR1L = 0xA8;
#define Clock1 RC5_bit
void interrupt()
{
if(CCP1IF_bit)
{
CCP1IF_bit = 0;// clear flag
Clock1 = 0;
}
if(TMR2IF_bit)
{
Clock1 = 1;
TMR2IF_bit = 0;//clear flag
TMR1H = 0x00;//Clear timer1
TMR1L = 0x00;
}
} // ISR...
void PORT_Init(void)
{
TRISA = 0xFF; // PORTA input
TRISB = 0b00000001; // PORTB output except RB0 & RB1
PORTB = 0x00; // all zero
TRISC = 0b00001000; // PORTC output
PORTC = 0x00; // all zero
}
void main()
{
PORT_Init(void);
// Timer2 settings for 7ms interrupt
T2CON = 0x36;
PR2 = 223; // 10 ms time
TMR2IE_bit = 1;
INTCON = 0xC0;
// compare module settings...
CCP1CON = 0b00001011;// trigger special event
CCP1IE_bit = 1;
CCPR1L = 0xA8;
CCPR1H = 0x31;
//timer 1 settings...
T1CON = 0x01;
TMR1IF_bit = 0;
while(1)
{
#define Clock1 RC5_bit
#define Clock2 RC6_bit
unsigned short flag=0;
void interrupt()
{
if(CCP1IF_bit)
{
CCP1IF_bit = 0;// clear flag
Clock1 = 0;
Clock2 = 0;
}
if(TMR2IF_bit)
{
TMR2IF_bit = 0;//clear flag
TMR1H = 0x00;//Clear timer1
TMR1L = 0x00;
if(flag)
{
Clock1 = 1;
flag=~flag;
}
else
{
Clock2 = 1;
flag=~flag;
}
}
} // ISR...
void PORT_Init(void)
{
TRISA = 0xFF; // PORTA input
TRISB = 0b00000001; // PORTB output except RB0 & RB1
PORTB = 0x00; // all zero
TRISC = 0b00001000; // PORTC output
PORTC = 0x00; // all zero
}
void main()
{
PORT_Init(void);
// Timer2 settings for 7ms interrupt
T2CON = 0x36;
PR2 = 223; // 10 ms time
TMR2IE_bit = 1;
INTCON = 0xC0;
// compare module settings...
CCP1CON = 0b00001011;// trigger special event
CCP1IE_bit = 1;
CCPR1L = 0xA8;
CCPR1H = 0x31;
//timer 1 settings...
T1CON = 0x01;
TMR1IF_bit = 0;
while(1)
{
} // while
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 if(CCP1IF_bit) { CCP1IF_bit = 0;// clear flag Clock1 = 0; Clock2 = 0; LCD_Lock = 1; } if(TMR2IF_bit) { if(oscillation) { if(!clock_cycle) { Clock1 = 1; Clock2 = 0; } if(clock_cycle) { Clock1 = 0; Clock2 = 1; } clock_cycle = ~clock_cycle; } else { Clock1 = 0; Clock2 = 0; } LCD_Lock = 0; // for timer mechanism.... TMR2IF_bit = 0;//clear flag TMR1H = 0x00;//Clear timer1 TMR1L = 0x00; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 void interrupt() { if(CCP1IF_bit) { CCP1IF_bit = 0;// clear flag Clock1 = 0; Clock2 = 0; LCD_Lock = 1; } if(TMR2IF_bit) { if(oscillation) { if(!clock_cycle) { Clock1 = 1; Clock2 = 0; } if(clock_cycle) { Clock1 = 0; Clock2 = 1; } clock_cycle = ~clock_cycle; } else { Clock1 = 0; Clock2 = 0; } LCD_Lock = 0; // for timer mechanism.... TMR2IF_bit = 0;//clear flag TMR1H = 0x00;//Clear timer1 TMR1L = 0x00; } /*if(INTF_bit && !oscillation) { Charging_Clk = ~Charging_Clk; LCD_Lock = 0; INTF_bit = 0; }*/ } // ISR...
Code C - [expand] 1 2 3 4 5 void Trick_Delay(void) { while(LCD_Lock==0); Delay_ms(2); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 void LCD_Parameter(short LCD_message) { if(LCD_message==0) { Trick_Delay(void); Lcd_Out(1,1,"ALL_OFF "); } if(LCD_message==1) { Trick_Delay(void); Lcd_Out(1,1,"IPS_RUN "); } if(LCD_message==2) { Trick_Delay(void); Lcd_Out(1,1,"MAINS_ON"); } if(LCD_message==3) { Trick_Delay(void); Lcd_Out(1,1,"CHARGING"); } if(LCD_message==4) { Trick_Delay(void); Lcd_Out(1,1,"CH_FULL "); } if(LCD_message==5) { Trick_Delay(void); Lcd_Out(1,1,"LOW_BATT"); } if(LCD_message==6) { Trick_Delay(void); Lcd_Out(1,1,"OVERLOAD"); } Delay_ms(50); }
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?