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.

output on any pin when 2digit counter is zero

Status
Not open for further replies.

dasinesnaps

Newbie level 5
Joined
Mar 6, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,376
hey all ive been working on this circuit i found in one site, a 2 digit up down counter. i'm using this in conjunction with an IR module to replace the UP and DOWN switch with IR signals ( i've a transmitter and receiver for the same )... now i'm stuck here because i'm new to programming:roll:, i want output high in one pin when the 2digit (seven segment) counter is ZERO. i doubt whether it can be done on the circuit:!:, i mean a small tweak in the program might do it.. can anyone help me plz.. :smile::smile:

i saw this snippet on a program, thought it might be helpfull, wht do you think ?? wht does it do anyway ?

Main
movf units,1
btfss 03,2 ;test zero flag flag=1 when file=0
goto $+6
movf tens,1
btfss 03,2
goto $+3
bsf portA,6 ;make pin 15 HIGH
goto $+2
bcf portA,6

this is the main website i used to program and implement the circuit, it works fine, plz help me with the ''counter zero_ high output'' portion guys.. :)))

http://talkingelectronics.com/projects/2DigitUpDwnCounter/2DigitUpDwnCounter-1.html
 

Have you read all details there? :roll:
See the part about:
'' Adding ALARM
The program can be modified to produce an alarm when the count reaches "00."
The files for this are:’’
 

i really appreciate that you replied sir, but i already read and lookd into those files. it is from there i got the snippet. but the program they gave include a dice program and a random number program in it which is clearly not needed for me. can you please lead me with some spark about how to include it in my current program ?? the "counter reaching zero" part only.. i'm trying to stu dy programmin these days i'm doin a lill research of my own programmin and re_programmic the pic :razz::razz: but it doesn't seem to work out even if i'm gainin knwledge :(
 

Attachments

  • upndown.txt
    5.1 KB · Views: 43

i really appreciate that you replied sir, but i already read and lookd into those files. it is from there i got the snippet. but the program they gave include a dice program and a random number program in it which is clearly not needed for me. can you please lead me with some spark about how to include it in my current program ?? the "counter reaching zero" part only.. i'm trying to stu dy programmin these days i'm doin a lill research of my own programmin and re_programmic the pic :razz::razz: but it doesn't seem to work out even if i'm gainin knwledge :(


Hi,

Before following that site and possibly wasting your time, you may want to read this and similar posts
http://www.electro-tech-online.com/members-lounge/104925-help-colin-mitchell-talkingelectronics-com.html


For a good free assembler course that is directly supported by author have a look at this well known site

http://www.winpicprog.co.uk/pic_tutorial.htm


Another good free tutorial for Assembler and C is here
**broken link removed**
 

Hi,

Before following that site and possibly wasting your time, you may want to read this and similar posts
http://www.electro-tech-online.com/members-lounge/104925-help-colin-mitchell-talkingelectronics-com.html

i regret, shall i remove the files and use the webpage only for reference ?
For a good free assembler course that is directly supported by author have a look at this well known site

http://www.winpicprog.co.uk/pic_tutorial.htm


Another good free tutorial for Assembler and C is here
**broken link removed**

i will look into it sir, will text u back. thanks.
 

sir i'm having a huge delay on the project, i must travel a bit to get the pic programmd. i made a simple serial progrmmer of my own but serial cable is long gone, i mi8 get a serial jack soon. will post afterwards. regrds, das.
 

sir,
i made some changes in the program, it worked but i'm getting very little current on the output pin 15.
this is the program code...


;code protection - off
;low-voltage programming - off
;power-up timer - on
;watchdog timer - off
;use internal RC for 4MHz - all pins for in-out


;****************************************************************
; variables - names and files
;****************************************************************


;Files for F628 start at 20h


temp1 equ 20h ;for delay
temp2 equ 21h ;for delay
SwUp equ 22h ;
SwDwn equ 23h ;
units equ 24h ;
tens equ 25h ;
Sw_Flag equ 26h ;


;****************************************************************
;Equates
;****************************************************************
status equ 0x03
cmcon equ 0x1F
rp1 equ 0x06
rp0 equ 0x05
portA equ 0x05
portB equ 0x06

;****************************************************************
;Beginning of program
;****************************************************************
reset org 00 ;reset vector address
goto SetUp ;goto SetUp


table addwf PCL,F ;02h,1 add W to program counter
retlw b'00111111' ; "0" -|F|E|D|C|B|A
retlw b'00000110' ; "1" -|-|-|-|C|B|-
retlw b'01011011' ; "2" G|-|E|D|-|B|A
retlw b'01001111' ; "3" G|-|-|D|C|B|A
retlw b'01100110' ; "4" G|F|-|-|C|B|-
retlw b'01101101' ; "5" G|F|-|D|C|-|A
retlw b'01111101' ; "6" G|F|E|D|C|-|A
retlw b'00000111' ; "7" -|-|-|-|C|B|A
retlw b'01111111' ; "8" G|F|E|D|C|B|A
retlw b'01101111' ; "9" G|F|-|D|C|B|A


;****************************************************************
;* port A and B initialisation *
;****************************************************************

SetUp bsf status,rp0
movlw b'00001100' ;Make RA0,1 out RA2,3 in
movwf 05h
clrf 06h ;Make all RB output
bcf status,rp0 ;select programming area - bank0
movlw b'10000000' ;Turn off T0CKI, prescale for TMR0 = 1:
movwf option_reg
clrf portB ;Clear Port B of junk*
clrf units ;zero the units file
clrf tens ;zero the tens file
clrf Sw_Flag
movlw 07h ;turn comparators off and enable
movwf cmcon ; pins for I/O functions
goto Main



;****************************************************************
;* Delay 10mS 10 x 1,000uS *
;****************************************************************



D_10mS movlw 0Ah
movwf temp2
D_a nop
decfsz temp1,1
goto D_a
decfsz temp2,1
goto D_a
retlw 00


Up btfsc Sw_Flag,2
retlw 00
bsf Sw_Flag,2
incf units,1
movlw 0Ah ;put 10 into w
xorwf units,0 ;compare units file with 10
btfss status,2 ;zero flag in status file. Will be set if units is 10
retlw 00
clrf units
incf tens,1
movlw 0Ah ;put 10 into w
xorwf tens,0 ;compare units file with 10
btfsc status,2 ;zero flag in status file. Will be set if tens is 10
clrf tens
retlw 00 ;display passes 99 but not below 0



Dwn btfsc Sw_Flag,3
retlw 00
bsf Sw_Flag,3
decf units,1
movlw 0FFh ;put FFh into w
xorwf units,0 ;compare units file with FFh
btfss status,2 ;zero flag in status file. Will be set if units is 10
retlw 00
movlw 09
movwf units ;put 9 into units file
decf tens,1
movlw 0FFh ;put 0FFh into w
xorwf tens,0 ;compare tens file with 0FFh
btfsc status,2 ;zero flag in status file. Will be set if tens is 0FFh
goto $+2 ;tens file is 0FFh
retlw 00
clrf tens
clrf units
retlw 00 ;display not below 0


;****************************************************************
;* Main *
;****************************************************************

Main movf units,1
btfss 03,2 ;test zero flag flag=1 when file=0
goto $+6
movf tens,1
btfss 03,2
goto $+3
bsf portA,6 ;make pin 15 HIGH
goto $+2
bcf portA,6 ;over

btfss portA,2 ;test switch-press for UP
call Up ;UP switch pressed
btfss portA,3 ;test switch-press for Down
call Dwn ;Down switch pressed
movlw b'00000001' ;Make RA0 HIGH for units drive
movwf portA
movf units,0 ;copy unit value into w
call table ;unit display value will return in w
movwf portB ;output units value
call D_10mS ;call delay
clrf portB ;clear display
movlw b'00000010' ;Make RA1 HIGH for tens drive
movwf portA
movf tens,0 ;copy tens value into w
call table ;tens display value will return in w
movwf portB ;output tens value
call D_10mS ;call delay
clrf portB ;clear display
btfsc portA,2 ;bit will be zero when sw is pressed
bcf Sw_Flag,2
btfsc portA,3 ;bit will be zero when sw is pressed
bcf Sw_Flag,3
goto Main

END


all copyright of the program belongs to http://talkingelectronics.com

i measured the voltage across the output pin, it is in the order of millivolts. other output pins are workin well and good.
the red color portion is that i changed. now i get a very dim led light when counter is 00 . is there anyway i can drive a relay using the output ? can i improve it anyway ?
 

Hi,

For someone trying to learn I personally think that code is terrible with its addressing the system registers by their location rather than Name.
eg , btfss 03,2 is much easier as btfss STATUS,Z

Using the goto $+ can also be confusing, using labels is much clearer.

eg goto $+5 , goto step2


RA6 is a multiple function pin, and if set for Digital I/O use it will sink or source 25ma, easily driving a standard led via a resistor , though for a relay is more usual to use a transistor to handle the extra current and voltage.

The code you use does not have any Configuration instructions in the code, just a few comment lines at the top.
If nothing is specified in the code, then you can manually select the correct Configuration in drop down menu of MPlab - CONFIGURE, COFIGURATION BITS
Notice the little check box at the top left must be turned off as shown.

Only when you select the Internal oscillator will RA6 and RA7 become digital I/O pins.

Here are the settings I think should work with that circuit.


EDIT Sorry the screenshot I posted originally was wrong - here is the correct one
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    60.3 KB · Views: 105
Last edited:

__Config _cp_off & _lvp_off & _pwrte_on & _wdt_off & _intRC_osc_noclkout & _mclre_off
these are the config bits sir
 

Hi,

For someone trying to learn I personally think that code is terrible with its addressing the system registers by their location rather than Name.
eg , btfss 03,2 is much easier as btfss STATUS,Z

Using the goto $+ can also be confusing, using labels is much clearer.

eg goto $+5 , goto step2
that was confusing indeed, u threw a bit of light :) thankss :)


RA6 is a multiple function pin, and if set for Digital I/O use it will sink or source 25ma, easily driving a standard led via a resistor , though for a relay is more usual to use a transistor to handle the extra current and voltage.
RA6 is set for I/O, internal osc is selected sir.

The code you use does not have any Configuration instructions in the code, just a few comment lines at the top.
i didnt posted them, thought it could be read from the comments itself, the bits are posted here.
__Config _cp_off & _lvp_off & _pwrte_on & _wdt_off & _intRC_osc_noclkout & _mclre_off

sir can u help me about the very very low voltage on RA6 ? actually the intended output is now got after i programmed the pic with the program attached but getting very low voltage and current in the pin 15
 

Attachments

  • 2digit.asm.txt
    5.4 KB · Views: 47

that was confusing indeed, u threw a bit of light :) thankss :)



RA6 is set for I/O, internal osc is selected sir.


i didnt posted them, thought it could be read from the comments itself, the bits are posted here.
__Config _cp_off & _lvp_off & _pwrte_on & _wdt_off & _intRC_osc_noclkout & _mclre_off

sir can u help me about the very very low voltage on RA6 ? actually the intended output is now got after i programmed the pic with the program attached but getting very low voltage and current in the pin 15



Hi,

Ok so your config statement is actually in the code .

I think then what is happening is your BSF RA6 to ON, but look at the code shortly following that, movlw b'00000001' ;Make RA0 HIGH for units drive they are turning RA0 to high, but all other bits of PORTA to LOW.

RA0 and RA1 are constantly switched on and off to select the 7 segment digits.

Because the routine is a constant loop your BSF is turning on RA6 for just a few instruction, then off by the rest of the routines loop, which all happens in a few milliseconds, so the BSF / 5v on the RA6 is only there for a few nano seconds every few milliseconds, hence you very low reading on the voltmeter.

You will have to modify those instruction to PORTA so that instead of changing the whole of PORTA they just change the relevant BITs with the BSF and BCF instructions.

Think you can see why its generally better to write you own code rather than trying to break into foreign code.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top