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
/*******************************************************************************
MCU PIC16F73 , XTAL: 10MHz
Program written by Engr. Mithun K. Das
Email: mithun060@gmail.com Cell: 01722448270
******************************************************************************/
// LCD module connections
sbit LCD_RS at RC7_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISC7_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
#define Clock1 RC5_bit
#define Clock2 RC6_bit
float Battery;
unsigned int long_bat;
unsigned int adc_rd0,fb=5;
unsigned short oscillation,ch_start;
unsigned int os_cnt,feedback,ch_cnt,current;
void Get_Battery(void);
void Display_Battery(void);
void interrupt()
{
if(oscillation==1)
{
os_cnt++;
while(os_cnt<=3+feedback)
{
Clock2 = 0;
Clock1 = 0;
break;
}
while(os_cnt>=3+feedback && os_cnt<=53-feedback)
{
Clock2 = 1;
Clock1 = 0;
break;
}
while(os_cnt>=53-feedback && os_cnt<=59+feedback)
{
Clock2 = 0;
Clock1 = 0;
break;
}
while(os_cnt>=59+feedback && os_cnt<=106-feedback)
{
Clock2 = 0;
Clock1 = 1;
break;
}
while(os_cnt>=106-feedback)
{
Clock2 = 0;
Clock1 = 0;
break;
}
while(os_cnt==109)
{
os_cnt=0;
break;
}
}
TMR1IF_bit = 0;
TMR1H = 0xFE;
TMR1L = 0xEE;
}
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
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xFE;
TMR1L = 0xEE;
TMR1IE_bit = 1;
INTCON = 0xC0;
while(1)
{
Get_Battery(void);
Display_Battery(void);
oscillation = 1;
// feedback...
if(adc_rd0==51)
{
feedback = feedback;
}
else
{
if(adc_rd0<57 && adc_rd0>45)
{
if(adc_rd0>51)
{
if(fb<15)
{
fb = fb+1;
}
else
{
fb = fb;
}
}
if(adc_rd0<51)
{
if(fb>1)
{
fb = fb-1;
}
else
{
fb = fb;
}
}
}
else
{
if(adc_rd0>=57)
{
if(fb<15)
{
fb = fb+5;
}
else
{
fb = fb;
}
}
if(adc_rd0<=45)
{
if(fb>1)
{
fb = fb-5;
}
else
{
fb = fb;
}
}
}
feedback = fb;
}
} // while
}// void main
void Get_Battery(void)
{
ADCON0=0b00011001;
Battery = (float) ADC_Read(3)*0.0915;
long_bat = (int) ADC_Read(3)*.915;
}
void Display_Battery(void)
{
char Mess_Battery[]="B: . V";
Mess_Battery[2] = (long_bat/100) + 48;
Mess_Battery[3] = ((long_bat/10)%10) + 48;
Mess_Battery[5] = ((long_bat)%10) + 48;
Lcd_Out(1,10,Mess_Battery);
Delay_ms(50);
}
Code C - [expand] 1 Lcd_Out(1,10,Mess_Battery);
char Mess_Battery[]="B: . V";
Mess_Battery[2] = (long_bat/100) + 48;
Mess_Battery[3] = ((long_bat/10)%10) + 48;
Mess_Battery[5] = ((long_bat)%10) + 48;
Lcd_Out(1,10,Mess_Battery);
Delay_ms(50);
Code C - [expand] 1 2 3 char txt3[] = "Mess_Battery"; Lcd_Out(1,1,txt3);
Code C - [expand] 1 char Mess_Battery[]="B: . V";
T1CON.TMR1ON = 0; //Switch OFF TMR1
TMR1H = 0xFE;
TMR1L = 0xEE;
T1CON.TMR1ON = 1; //Switch ON TMR1
hello,
What is the purpose of the code inside the interrupt .. Step motor control ?
With FOSC=10MHz you have FFFF-FEEE=> 273 cycles *4/10 => 109µS to do this job..
(or 274 ? 0000-FEEE ?)
try to mesure the executing time of inside interrupt... to know, what is the effective load of your MCU
and so, find out remaining time at disposal to do ground Job ( as LCD display).
I think, you don't have enough time in the main to treat LCD, without disturbing each necesseray timing (delay)
to correctly drive it.
Try with a more powerfull PIC .. ie 18F Q10MHz with PLL => 40MHz as FOSC or 16x4=64MHz
or maybe you can organise your program elsewhere , to treat a part of code inside the main instead inside interrupt.
Maybe bank switching is causing the problem. Do you get "IRP_bit must be set manually to access xyz" message in mikroC Compiler. If yes then use CopyConst2Ram or change to PIC18F.
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?