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.

Problem with programming counter using Proton

Status
Not open for further replies.

Amr sherif

Newbie level 4
Joined
Nov 25, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
Hi all , i am New here and i have problem with programing counter with proton program , i am using basic language . My project is to use an analoge to digital converter in Pic 16f877a to calculat the temp by using Lm35 and to make alarm when the Temp reatches a certain value, the problem is i canot declare the Puch button to the program , and also i want to know how to declare the puch button to the micro ( Which port ). Plz replay fast Thx :grin:

The program :

Device 16F877A
XTAL 4
LCD_RSPIN PORTC.0
LCD_ENPIN PORTC.1
LCD_INTERFACE 8
LCD_DTPIN PORTB.0
LCD_LINES 2
Dim name As Byte

Dim s1 As Byte
Dim s2 As Byte
Dim y As Byte
loop:
Button 0,0,255,250,name,0,nopress
Print "F"
nopress:
GoTo loop
 

you can easily use like this other then button command:

Code:
Device 16F877A
XTAL 4
LCD_RSPIN PORTC.0
LCD_ENPIN PORTC.1
LCD_INTERFACE 8 
LCD_DTPIN PORTB.0
LCD_LINES 2

start:

if portb.0 = 0 then 
print "f"
else
cls
delayms 100
end if

goto start

or you really want to use button?

goto mywebsite..i have some tutorial off basic instruction you should understand..

thelocxresearch.tk
 
Last edited:

Thx Alot lockman_akim but i have to use Puch button that what my profesor told me :( Any way thx alot for reply :D
 

start:

Button PORTB.0 , 0,0,0, BTNVAR, 0,nopress
Print "f"

nopress:
GoTo start
 

:D :D Thx again but thats now what i want , i have done this befor several times, i need it when i press on the button prints F, that the New thing in the program :D :D
 

just ad the function below the BUTTON command..

hope it help u..
 

i did,it print the f , with out pressing :D

Device 16F877A
XTAL 4
LCD_RSPIN PORTC.0
LCD_ENPIN PORTC.1
LCD_INTERFACE 8
LCD_DTPIN PORTB.0
LCD_LINES 2
Dim BTNVAR As Byte
Dim name As Byte
Dim y As Byte

start:

Button PORTD.0 , 0,0,0, BTNVAR, 0,nopress
If PORTD.0 = 1 Then y=y+1
DelayMS 100
Print Dec y

nopress:
GoTo start

thats what i did :D
 

Syntax

BUTTON Pin , DownState , Delay , Rate , Workspace , TargetState , Label

Overview

Debounce button input, perform auto-repeat, and branch to address if button is in target state. Button circuits may be active-low or active-high.

Operators
Pin - a PORT.BIT, constant, or variable (0 - 15), that specifies the I/O pin to use. This pin will automatically be set to input.
DownState - a variable, constant, or expression (0 or 1) that specifies which logical state occurs when the button is pressed.
Delay - a variable, constant, or expression (0 - 255) that specifies how long the button must be pressed before auto-repeat starts. The delay is measured in cycles of the Button routine. Delay has two special settings: 0 and 255. If Delay is 0, Button performs no debounce or auto-repeat. If Delay is 255, Button performs debounce, but no auto-repeat.
Rate - a variable, constant, or expression (0 - 255) that specifies the number of cycles between auto-repeats. The rate is expressed in cycles of the Button routine.
Workspace - a byte variable used by Button for workspace. It must be cleared to 0 before being used by Button for the first time and should not be adjusted outside of the Button command.
TargetState - a variable, constant, or expression (0 or 1) that specifies which state the button should be in for a branch to occur. (0 = not pressed, 1 = pressed).
Label - a label that specifies where to branch if the button is in the target state.
Example

DIM BTNVAR AS BYTE ' Workspace for BUTTON instruction.

Loop: ' Go to NoPress unless BTNVAR = 0.
BUTTON 0 , 0 , 255 , 250 , BTNVAR, 0 , NoPress
PRINT "* "
NoPress:
GOTO Loop

Notes

When a button is pressed, the contacts make or break a connection. A short (1 to 20ms) burst of noise occurs as the contacts scrape and bounce against each other. Button's debounce feature prevents this noise from being interpreted as more than one switch action.

Button also reacts to a button press the way a computer keyboard does to a key press. When a key is pressed, a character immediately appears on the screen. If the key is held down, there's a delay, then a rapid stream of characters appears on the screen. Button's auto-repeat function can be set up to work much the same way.

Button is designed for use inside a program loop. Each time through the loop, Button checks the state of the specified pin. When it first matches DownState, the switch is debounced. Then, as dictated by TargetState, it either branches to address (TargetState = 1) or doesn't (TargetState = 0).

If the switch stays in DownState, Button counts the number of program loops that execute. When this count equals Delay, Button once again triggers the action specified by TargetState and address. Thereafter, if the switch remains in DownState, Button waits Rate number of cycles between actions. The Workspace variable is used by Button to keep track of how many cycles have occurred since the pin switched to TargetState or since the last auto-repeat.

Button does not stop program execution. In order for its delay and auto repeat functions to work properly, Button must be executed from within a program loop.
Code:
        Dim BTNVAR As Byte
        Clear
        Cls
        start:
        
        Button PORTB.0 , 0 , 0 , 0 , BTNVAR, 0 , nopress 
        DelayMS 20
        Print "f"
        
        nopress:

        GoTo start
 

Thx lockman_akim for helping , thats what i have read in the proton help , and of course it didnot work :D:D Thx
 

yes it work..just put the delay before it start the function below BUTTOn command..it repeatly print f because the debounce off the switch..

---------- Post added at 18:35 ---------- Previous post was at 18:32 ----------

do like this:


Device 16F877A
XTAL 4
LCD_RSPIN PORTC.0
LCD_ENPIN PORTC.1
LCD_INTERFACE 8
LCD_DTPIN PORTB.0
LCD_LINES 2
Dim BTNVAR As Byte
Dim y As Byte
clear
start:

Button PORTD.0 , 0,0,0, BTNVAR, 0,nopress
delayms 50
If PORTD.0 = 1 Then y=y+1
DelayMS 100
Print Dec y

nopress:
GoTo start

---------- Post added at 18:43 ---------- Previous post was at 18:35 ----------

ok..i think it perfect now..

Code:
Device 16F877A
XTAL 4
LCD_RSPIN PORTC.0
LCD_ENPIN PORTC.1
LCD_INTERFACE 8 
LCD_DTPIN PORTB.0
LCD_LINES 2
Dim BTNVAR As Byte
Dim y As Byte
clear
y = 0
start:

Button PORTD.0 , 0,0,0, BTNVAR, 0,nopress
DelayMS 100
y=y+1
Print Dec y 

nopress:
GoTo start
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top