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.

[SOLVED] Help with Button in Mikroc

Status
Not open for further replies.

spider7

Newbie level 4
Newbie level 4
Joined
Feb 5, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,373
Hello Everybody,

I hope someone will help me in resolving my problem. I am new to Microcontroller and Mikroc. My project details in short is given as below.

1. I am using PIC16F886 for this project.
2. I have setup 2 ADC on PORT A0 and A1 for input.
3. I have setup a Button(Push to on Switch) on PORT A1.
4. I have setup LCD 2 x 16 on PORT C.
5. Finally I am using 8Mhz internal osc.

Now I read 2 values from A0 and A1 in my while loop. Now what exactly I want is when I press switch this loop should stop working and again when I press the same for second time the loop should start working.

below is the code :

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
while(1)
          {
          unsigned int v,vp,ip,i;
          char *volt = "00.00";
          char *current = "0.000";
          char *res = "0.000";
 
          v = ADC_Read(0);
          i = ADC_Read(1);
          i = ((i*4.89)/0.33); //0.47;
          v = ((v*4.89)/27)*254;
 
          if(v!=vp || i!=ip || e!=r )
          Lcd_Cmd(_LCD_CLEAR);
          vp = v;
          ip = i;
 
          volt[0] = look(v/10000);
          volt[1] = look((v/1000)%10);
          volt[3] = look((v/100)%10);
          volt[4] = look((v/10)%10);
          Lcd_Out(1,1,"Volt=");
          Lcd_Out(1,10,volt);
          Lcd_Out(1,18,"V");
 
          current[0] = look((i/1000)%10);
          current[2] = look((i/100)%10);
          current[3] = look((i/10)%10);
          current[4] = look(i %10);
          Lcd_Out(2,1,"Curr=");
          Lcd_Out(2,10,current);
          Lcd_Out(2,18,"A");
 
}



please help me in using switch to start and stop this loop.

Thankyou all in advance.
 
Last edited by a moderator:

Is there 8 MHz internal OSC available? Your variables should be declared at the beginning of the main() function or as global variables.
If your button is PORTA.F4 then it should be configured as digital input pin. You have to configure ANSELx and or ADCONx registers.

You cannot use A1 or any pin for both adc and also for button.



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
unsigned char readanddisplayadc =  0;
 
while(1){
    //Button Code
 
    if(PORTA.F4){
        Delay_ms(50);
        if(PORTA.F4){
            readanddisplayadc = 1;
        }
    }
    
    if(readanddisplayadc){
 
        //Your code inside while(1) loop here
        readanddisplayadc = 0;
 
    }
 
}

 
Last edited:
Thank you for quick reply. Can you give example for digital input and analog input config please.
 

Zip and post your mikroC project files and Circuit. I will fix it and post.

mikroC Code + Proteus file attached.

95259d1377288941-adc.png
 

Attachments

  • adc.rar
    93.7 KB · Views: 96
  • adc.png
    adc.png
    37.4 KB · Views: 138
Last edited:
Hello Jayanth,

You posted exactly what I am using and hence I didn't posted my project. The only change in mine is I am using voltage divider and current sense resistor. Rest all remains same.

Thank you for the post.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top