View previous topic :: View next topic |
Author |
Message |
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Sun Jun 17, 2007 2:27 pm Post subject: Need help with person counter project |
|
|
Hi guys i'm doing a project for school and i need to make a person counter. Now i have wrote the most of the program needed for te project.
The only thing i need now is to write a program that transfers the numbers from the counter to my 7 segment diplays and in between there are 74hc4094 as datashifters registers. Now i learned to write bascom in a month so i don't know much about how to write most things. I heard i needed to write an array or something but i don't know how to start . Can someone plz help me a bit to start creating an array for my project?
here's my program (i use an 89c2051 uc btw)
Dim Bteller As Byte
Dim Bingave As Byte
Bteller = 00
Do
P1.5 = 1
P1.7 = 0
P1.6 = 0
If P1.7 = 1 And P1.6 = 0 Then
Bteller = Bteller + 1
Print "persoon in" ; Bteller
Waitms 50
P1.5 = 0
Waitms 10
End If
If P1.6 = 1 And P1.7 = 0 Then
Bteller = Bteller - 1
If Bteller = 255 Then
Bteller = 0
End If
Print "person out " ; Bteller
Waitms 50
P1.5 = 0
Waitms 10
End If
Loop
End |
|
Back to top |
|
|
Gianni
Joined: 09 Jul 2004 Posts: 61 Location: Italy
|
Posted: Mon Jun 18, 2007 8:19 am Post subject: |
|
|
With a single 4094 you can count until 99; simply use makebcd and shiftout statement.
Do not forget to limit your counter to 99.
Regards |
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Mon Jun 18, 2007 10:23 am Post subject: |
|
|
can you give me an example, how to use makebcd and shiftout statements? because the examples in bascom are a bit unclear on how it works. We used 2 4094 btw. |
|
Back to top |
|
|
Gianni
Joined: 09 Jul 2004 Posts: 61 Location: Italy
|
Posted: Mon Jun 18, 2007 2:01 pm Post subject: |
|
|
Makebcd works from 0 to 99 decimal
To convert number greater then 99 a different approach is necessary.
I do not remember how the 4094 clock works;
eventually try shiftout Datapin,Clockpin,ones,4
Regards
Code: | dim Tmp1 as byte
dim Tmp2 as byte
dim hundreds as byte
dim tens as byte
dim ones as byte
dim value as byte
'
Datapin alias P1.7 'serial data input
Clockpin alias P1.6
Latch alias P1.5 '4094 latch enable
'
latch = 0
datapin = 0
clockpin = 0
'
do
input "value ",value
Tmp1 = value
hundreds = Tmp1 / 100
Tmp2 = hundreds * 100
Tmp1 = Tmp1 - Tmp2
tens = Tmp1 / 10
Tmp2 = tens * 10
ones = Tmp1 - Tmp2
'
print hundreds;tens;ones;" = "; value
shiftout Datapin,Clockpin,ones,3
shiftout Datapin,Clockpin,tens,3
shiftout Datapin,Clockpin,hundreds,3
latch = 1
nop 'update 4094 output
nop
latch = 0
loop |
|
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Mon Jun 18, 2007 2:49 pm Post subject: |
|
|
thx man! but i only need to count to 99 so if you can give me an example of makebcd then i can get to work!! |
|
Back to top |
|
|
Gianni
Joined: 09 Jul 2004 Posts: 61 Location: Italy
|
Posted: Tue Jun 19, 2007 7:30 am Post subject: |
|
|
Quote: | but i only need to count to 99 |
I suppose you do not use a bcd to 7 segment decoder but directly drive the display with the 4094.
Is that right ? |
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Tue Jun 19, 2007 8:01 am Post subject: |
|
|
Hey here is a link to our schematic of the counter. We don't use a decoder like you said.
u4 and u5 are the 7 segment display's |
|
Back to top |
|
|
Gianni
Joined: 09 Jul 2004 Posts: 61 Location: Italy
|
Posted: Tue Jun 19, 2007 9:05 am Post subject: |
|
|
Ok!
Try this.
Code: | Tmp1 = makebcd(value)
Tmp1 = Tmp1 and 15
Tmp1 = lookup(Tmp1,Bcd2_7seg)
shiftout Datapin,Clockpin,Tmp1,3 'send ones
Tmp1 = makebcd(value)
shift Tmp1,right,4
Tmp1 = lookup(Tmp1,Bcd2_7seg)
shiftout Datapin,Clockpin,Tmp1,3 'send tens
const Sa = 1 'segment a d0
const Sb = 2 'segment b d1
const Sc = 4
const Sd = 8
const Se = 16
const Sf = 32
const Sg = 64
const Sdot = 128 'dot d7
Bcd2_7seg:
data Sa+Sb+Sc+Sd+Se+Sf 'digit 0
data Sb+Sc 'digit 1
data Sa+Sb+Sg+Se+Sd 'digit 2
data Sa+Sb+Sc+Sd+Sg 'digit 3
'digit 4
'digit 5
'digit 6
'digit 7
'digit 8
'digit 9
|
|
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Wed Jun 20, 2007 7:35 am Post subject: |
|
|
i don't get it :S i used your program to controll the display but i don't get anything on my displays not even 1 segment lights up.
i did this:
************************************************************
Code: | Dim Bteller As Byte
Dim Tmp1 As Byte
Dim A As Byte , C As Byte
Bteller = 00
Do
P1.5 = 1
P1.7 = 0
P1.6 = 0
If P1.7 = 1 And P1.6 = 0 Then
Bteller = Bteller + 1
Print "persoon binnen " ; Bteller
Waitms 50
P1.5 = 0
Waitms 10
End If
If P1.6 = 1 And P1.7 = 0 Then
Bteller = Bteller - 1
If Bteller = 255 Then
Bteller = 0
End If
Print "persoon weg " ; Bteller
Waitms 50
P1.5 = 0
Waitms 10
End If
If Bteller = 99 Then
Bteller = 00
End If
A = 63
C = 6
Tmp1 = Makebcd(a)
Tmp1 = Tmp1 And 15
Tmp1 = Lookup(tmp1 , Bcd2_7seg)
Shiftout P3.3 , P3.4 , Tmp1 , 3 'send ones
Tmp1 = Makebcd(c)
Shift Tmp1 , Right , 4
Tmp1 = Lookup(tmp1 , Bcd2_7seg)
Shiftout P3.3 , P3.4 , Tmp1 , 3 'send tens
Const Sa = 1 'segment a d0
Const Sb = 2 'segment b d1
Const Sc = 4
Const Sd = 8
Const Se = 16
Const Sf = 32
Const Sg = 64
Const Sdot = 128 'dot d7
Bcd2_7seg:
Data Sa + Sb + Sc + Sd + Se + Sf 'digit 0
Data Sb + Sc 'digit 1
Data Sa + Sb + Sg + Se + Sd 'digit 2
Data Sa + Sb + Sc + Sd + Sg 'digit 3
Data Sb + Sc + Sf + Sg 'digit 4
Data Sa + Sc + Sd + Sf + Sg 'digit 5
Data Sa + Sc + Sd + Se + Sf + Sg 'digit 6
Data Sa + Sb + Sc 'digit 7
Data Sa + Sb + Sc + Sd + Se + Sf + Sg 'digit 8
Data Sa + Sb + Sc + Sd + Sf + Sg 'digit 9
Loop
End |
************************************************************* |
|
Back to top |
|
|
Gianni
Joined: 09 Jul 2004 Posts: 61 Location: Italy
|
Posted: Wed Jun 20, 2007 12:11 pm Post subject: |
|
|
You forget to latch data into 4094; pulse pin 1
P3.2 = 1
nop
nop
P3.2 = 0
Pin 15 of 4094 must be High; connect to +5v
IMHO is not a good idea drive all the 7 leds with a single resistor; use separate resistors
Regards |
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Thu Jun 21, 2007 7:39 am Post subject: |
|
|
well the thing is when i program a microcontroller with a program i got from my teacher (last project) the displays work. so it has to do something with the program. |
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Wed Jun 27, 2007 10:24 am Post subject: |
|
|
hey got another question for you:
why do you do tmp1 = tmp1 and 15 ?
btw i'm getting a few segments that are lighting up so the program almost works |
|
Back to top |
|
|
subar
Joined: 31 May 2007 Posts: 142 Location: kurdistan region
|
Posted: Wed Jun 27, 2007 1:50 pm Post subject: |
|
|
this is the code you can get benifet from and i had excuted it works correctly...
' port A 7 segment
' -------- ---------
' 0 -----------> a
' 1 -----------> b
' 2 -----------> c
' 3 -----------> d
' 4 -----------> e
' 5 -----------> f
' 6 -----------> g
'----------------------------------------------------------------
$regfile = "m16def.dat"
Config Porta = Output
Porta = 255
Dim I As Byte
Dim X(16) As Byte
Restore Value_table
For I = 1 To 16
Read X(i)
Next
Do
For I = 1 To 16
Porta = Not X(i)
'Porta = X(i)
Waitms 500
Next
Loop
End
Value_table:
Data &H40 , &H79 , &H24 , &H30 , &H19 , &H12 , &H02 , &H78
Data , &H00 , &H10 , &H08 , &H03 , &H46 , &H21 , &H06 , &H0E _________________ many people know what to do,But few people do what they know.
Regards
subar |
|
Back to top |
|
|
Tripwire
Joined: 17 Jun 2007 Posts: 8
|
Posted: Thu Jun 28, 2007 7:32 am Post subject: |
|
|
thx man but can you give me m16def.dat? i don't have the file |
|
Back to top |
|
|
sakaz
Joined: 02 May 2007 Posts: 99
|
Posted: Thu Oct 15, 2009 12:18 am Post subject: |
|
|
Hi forum,
Hope you are doing well all. I have been working with Bascom AVR for last 2 years and i am so glad to learn alot of things from this great forum. I must thank all of you.
These days i am working on a project with the 7 Segment (Liquid Crystal Display) 6 1/2". and trying to drive with the Cd4094, CD4543 & CD4514 as per attached schematic.
I want to display my result on the 6 digit display but i am having some problem.
I want to lacht the CD4514 first to select the digit and then CD4543 to show the data but i cant.
'-----------------------------------------------------------------------------------------
'name : shift.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : example for SHIFTIN and SHIFTOUT statement
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
$regfile = "m8def.dat" ' specify the used micro
$crystal = 4000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim L As Long
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Output
Sipo_sck Alias Portb.0 'port for sck 74hc
Sipo_din Alias Portb.1 'data serial input
Sipo_latch Alias Portb.2 'latch pin
Sipo_sck = 0 'initial out
Sipo_din = 0
Sipo_latch = 0
Dim Data_sipo As Byte
Data_sipo = 0
Do
Shiftout Sipo_din , Sipo_sck , Data_sipo , 1
Sipo_latch = 1
Waitms 100
Sipo_latch = 0
Wait 1
Shiftout Sipo_din , Sipo_sck , Data_sipo , 2 <---- LSB Shifted out first when Clock goes low.
Sipo_latch = 1
Waitms 100
Sipo_latch = 0
Waitms 100
Wait 1
Incr Data_sipo
Loop
End
But i inverse the data input lines as per:
11 ----- 2
12 ----- 3
13 ----- 21
14 ---- 22
Then it does work fine. Why i cant find the reason. please help.
Regards, |
|
Back to top |
|
|
|