combining projects in MikroC
Posted: 30 Mar 2017 18:23
hello
im a beginner and i have issues combining two projects to be run by one microcontroller. the code compiled but does not function as expected in proteus.this is my code
sbit LCD_RS at Rc0_bit;
sbit LCD_EN at Rc1_bit;
sbit LCD_D4 at Rc2_bit;
sbit LCD_D5 at Rc3_bit;
sbit LCD_D6 at Rc4_bit;
sbit LCD_D7 at Rc5_bit;
sbit LCD_RS_Direction at TRISc0_bit;
sbit LCD_EN_Direction at TRISc1_bit;
sbit LCD_D4_Direction at TRISc2_bit;
sbit LCD_D5_Direction at TRISc3_bit;
sbit LCD_D6_Direction at TRISc4_bit;
sbit LCD_D7_Direction at TRISc5_bit;
// End LCD module connections
char message1[] = "PHCN SOURCE VOLT ";
float voltage;
float val;
int voltage1;
int cnt;
char text[15];
char volt[4];
int timer=8;
void interrupt() {
if (TMR0IF_bit) {
cnt++; // increment counter
TMR0IF_bit = 0; // clear TMR0IF
TMR0 = 39;
}
}
void int_delay(){
if (cnt ==120) {
PORTB.F2 = ~PORTB.F2; // Toggle PORTB LEDs
timer--;
cnt = 0; // Reset cnt
inttostr( timer, text);
Lcd_Out(1,1,"conctn to source");
Lcd_Out(2,6,text);
Lcd_Out(2,7,"sec");
if(timer==0){ timer=0; intcon.T0IE=0; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,message1);}}}
void voltagecon(){
do {
voltage = ADC_Read(2);
val=(voltage*5)/1023;
voltage1 = (voltage * 5 * 65)/ (1023);
inttostr(voltage1,volt); // it converts integer value into string
Lcd_Out(2,1,"Voltage = ");
Lcd_Out(2,11,Ltrim(volt));
Lcd_Out(2,16,"V");
if(voltage1>260){
RB2_BIT=1;
Lcd_Out(2,1,"DANGER ");
DELAY_MS(1000); }
}
while(1);}
//
void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
TRISB = 0; // PORTB is output
PORTB.f2 = 1; // Initialize PORTB
TMR0 = 39; // Timer0 initial value
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0; // Initialize cnt
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00;
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
int_delay();
voltagecon ();
}}
please i need assistance
im a beginner and i have issues combining two projects to be run by one microcontroller. the code compiled but does not function as expected in proteus.this is my code
sbit LCD_RS at Rc0_bit;
sbit LCD_EN at Rc1_bit;
sbit LCD_D4 at Rc2_bit;
sbit LCD_D5 at Rc3_bit;
sbit LCD_D6 at Rc4_bit;
sbit LCD_D7 at Rc5_bit;
sbit LCD_RS_Direction at TRISc0_bit;
sbit LCD_EN_Direction at TRISc1_bit;
sbit LCD_D4_Direction at TRISc2_bit;
sbit LCD_D5_Direction at TRISc3_bit;
sbit LCD_D6_Direction at TRISc4_bit;
sbit LCD_D7_Direction at TRISc5_bit;
// End LCD module connections
char message1[] = "PHCN SOURCE VOLT ";
float voltage;
float val;
int voltage1;
int cnt;
char text[15];
char volt[4];
int timer=8;
void interrupt() {
if (TMR0IF_bit) {
cnt++; // increment counter
TMR0IF_bit = 0; // clear TMR0IF
TMR0 = 39;
}
}
void int_delay(){
if (cnt ==120) {
PORTB.F2 = ~PORTB.F2; // Toggle PORTB LEDs
timer--;
cnt = 0; // Reset cnt
inttostr( timer, text);
Lcd_Out(1,1,"conctn to source");
Lcd_Out(2,6,text);
Lcd_Out(2,7,"sec");
if(timer==0){ timer=0; intcon.T0IE=0; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,message1);}}}
void voltagecon(){
do {
voltage = ADC_Read(2);
val=(voltage*5)/1023;
voltage1 = (voltage * 5 * 65)/ (1023);
inttostr(voltage1,volt); // it converts integer value into string
Lcd_Out(2,1,"Voltage = ");
Lcd_Out(2,11,Ltrim(volt));
Lcd_Out(2,16,"V");
if(voltage1>260){
RB2_BIT=1;
Lcd_Out(2,1,"DANGER ");
DELAY_MS(1000); }
}
while(1);}
//
void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
TRISB = 0; // PORTB is output
PORTB.f2 = 1; // Initialize PORTB
TMR0 = 39; // Timer0 initial value
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0; // Initialize cnt
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00;
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
int_delay();
voltagecon ();
}}
please i need assistance