Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me to finish the program;timer-mikroc-pic

Status
Not open for further replies.

mailus

Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Activity points
2,706
Now I am doing a mini project to learn pic mcu through MIKROC.
so i am a beginner....

my project details
*adjustable timer to control a device.
*pic16f88
*using timer0




my doubt in a program..

I get inputs from user and calculate the interrupt routine value.

from the input i enter the value in character array ( char msg7[]="00"; )

now i want to calculate the interrupt routine value so i want to multiply the user input with 18 (msg7 * 18)
how to perform this multiplication operation using character array....
 

That will automatically happen; you multiply char will produce integer.
you can find more details on help of microC implicit conversion.
Hope this helps you.
 
  • Like
Reactions: mailus

    mailus

    Points: 2
    Helpful Answer Positive Rating
thank you... can you explain more about this with example

- - - Updated - - -

i converted the char into integer by using atoi command.... my problem solved.....
 

HI to all,

from your guidance I finish that timer using timer0. now i post the MICROC code and simulation file....please suggest some modification....what am wrong in that code....how to write a code in professional way....

I have doubt in the program while simulating the code initially LCD starts flickering how to avoid this?

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

//tact switch and relay ports
sbit ten at ra0_bit;
#define sten 0
sbit unit at ra1_bit;
#define sunit 1
sbit ss_select at ra2_bit;
#define s_ss_select 2

#define port porta
#define delay 20

sbit on_delay at ra3_bit;
sbit off_delay at ra4_bit;
sbit buzz at Rb6_bit;
sbit indication at rb7_bit;
//end of relay and switch connections

//message display
char msg1[]="ELECTRONIC TIMER";
char msg2[]="BY MAILUS";
char msg3[]="SET TIME=   MIN";
char msg4[]="TIMER RUNNING";
char msg5[]="OUTPUT ON";
char msg6[]="OUTPUT OFF!";
char msg7[]="00";
//END OF MESSAGE

//variable declaration
short int t,u,si;
bit io,k;
int cal,i,jj;
//end of variable declaration

//define intial state
void initial_state()
{
 k=0;
 lcd_cmd(_lcd_clear);
 lcd_out(1,2,msg3);
 lcd_out(2,1,msg6);
 on_delay=0;
 off_delay=1;
 buzz=0;
 indication=0;
 }
 //end of initial state


 //read input
void readinput()
  {
   if(si==0)
   {
    if(button(&port,sten,delay,1))
    {
     t++;
     if(t==10) t=0;
    }while(ten=~ten);
    if(button(&port,sunit,delay,1))
    {
     u++;
     if(u==10) u=0;
    }while(unit=~unit);
   }
   if(button(&port,s_ss_select,delay,1))
   {
    si=~si;
    }while(ss_select=~ss_select);
  }
 //end of read input




//timer function through interrupt

void interrupt()
 {
  i++;
  if(i==cal)
  {
   io=~io;
   i=0;
  }
   intcon.tmr0if=0;
   tmr0=39;
  }
 //end of timer function


// display function
 void display()
 {
  msg7[0]=t+48;
  msg7[1]=u+48;
  if(k!=1)
  {
  lcd_out(1,11,msg7);
  }
}
 
//end of display
 


 void output()
 {

 lcd_out(2,1,msg5);
 io=0;
 k=~k;
 on_delay=1;
 off_delay=0;
 DELAY_MS(1000);
 }

void main()
{
 trisa=0x07;
 trisb=0x00;
 porta=0x10;
 portb=0x00;
 ansel=0x00;
 cmcon=0x07;
 tmr0=39;
 i,u,si,io,cal,jj,k=0;
 option_reg=0x07;
 intcon=0x80;
 lcd_init();
 lcd_cmd(_lcd_clear);
 lcd_cmd(_lcd_cursor_off);
 lcd_out(1,1,msg1);
 lcd_out(2,1,msg2);
 delay_ms(1000);
 lcd_cmd(_lcd_clear);
 do
 {
  void initial_state();
  readinput();
  display();
  delay_ms(50);
  if(si)
  {
   jj = atoi(msg7);
   cal= (jj * 1080);
   if(jj!=0&&k==0)
   {
    intcon.tmr0ie=1;
    lcd_out(2,1,msg4);
    if(io)
    {
    lcd_cmd(_lcd_clear);
     output();
    }
    }
   } 
   else 
   {
    intcon.tmr0ie=0;
    i=0;
    initial_state();
   }
 }while(1);
  }



CODE and DSN file attached here..........

waiting for your valuable reply.........
 

Attachments

  • timer to EDA.rar
    16.9 KB · Views: 83

Hi,
Add comments to your code;(like what does it do, meaning of variables & parameters, when to alter the code....) that will make easy to understand your code. Also it will help you in debugging.
I guess, your initial LCD message flicker since it's being written on LCD repeatedly by the main loop. You can check it by step-by-step running in proteus-ISIS simulation.
Hope this would help you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top