Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

push button algorithm using PIC

Status
Not open for further replies.

herry2

New Member
hello guys

I'm design a circuit which have 6 input of ADC, each value of input ADC will be display in LCD, so for that purpose I use 1 push button which have function has selector ( when I push the button one time LCD will display value on first ADC input, when I push the button twice LCD will display value on second ADC, and so on). but I don't have a clue for the algorithm. I'm just a newbie in PIC, btw I'm using assembler languange for program this PIC.

can you help me guys

cheers
raka
 
If you merely want to cycle through the values then you could

disp1
read adc1
display value 1
is button pressed ?
no = goto disp1
yes
disp2
read adc2
display value 2
wait for button release
is button pressed ?
no = goto disp2
yes
~
disp6
read adc6
display value 6
wait for button release
is button pressed ?
no = goto disp6
yes
goto disp1 ;start from 1 again

There are many ways to do the same thing but as a newbie it may be easier to do it like this to understand the flow you require.
 
That's a lot of code replication. In C like pseudo code
Code:
disp = 1
for(;;) {  // this is a loop
    sample disp
    display disp
    if(button pressed)
        disp = disp + 1
        if(disp> 6)
            disp = 1
}
you will need to debounce the switch.
 
thanks philba, but I'm using assembler languange. How to use that C algorithm in assembler languange?

regards
raka
 
thanks philba, but I'm using assembler languange. How to use that C algorithm in assembler languange?

regards
raka

hi,
The algorithm that 'Gordz' has posted will give the result you want.

Are you now saying you want it coded in assembler language.?
 
hi
I'm still working out on 'Gordz' algorithm using assembler languange. Philba give me a new algorithm, so I'm confuse which algorithm I can use? I'm still newbie in programming so if you give me the sample code it will helpfull.

regards
raka
 
hi
I'm still working out on 'Gordz' algorithm using assembler languange. Philba give me a new algorithm, so I'm confuse which algorithm I can use? I'm still newbie in programming so if you give me the sample code it will helpfull.

regards
raka

hi,
As you are using assembler here is a sample program for 3 keys.

To enable you to follow it, its written in Basic, which creates the assembler code, so the annotation may help a little.:)

EDIT: added the *.bas
 

Attachments

  • demo1.asm
    1.9 KB · Views: 155
  • demo1.txt
    721 bytes · Views: 168
Last edited:
Hi

Thanks, I will try that algorithm.
There are many ways to do the same thing but as a newbie it may be easier to do it like this to understand the flow you require.

__________________________________________________________________
Arnold
Gmail Rocks Yahoo Mail Rocks
 
Hii
thanks Gordz, I have try your algorithm and succedd. Btw does anyone who now to set pwm frekwency? I have written assembler but the max frekwency just 71 kHZ, how to increase frekwency pwm to more than 100 kHz ?

init_pwm
bsf STATUS,RP0;
movlw 0x0E;
movwf PR2;
bcf TRISC,0x02;
bcf STATUS,RP0;
movlw 0x2F;
movwf CCPR1L;
movlw 0x1C;
movwf T2CON;
movlw 0x0C;
movwf CCP1CON;
return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top