Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

kiddieride music box

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
kiki

Bascom Member



Joined: 06 Dec 2013
Posts: 21

blank.gif
PostPosted: Mon Mar 09, 2015 3:44 pm    Post subject: kiddieride music box Reply with quote

hi, I just want to sharing my program i made..
here i make the program use for kiddierides machine.the hardware i use:atmega8,mp3 player(i use mp3 player cause i can't make the program using sd card Smile ), 7segment for digital timer.and here is the code:

$regfile = "m8def.dat"
$crystal = 4000000
'$sim
Config Portb = Output
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.3 = Output

Config Pind.0 = Input
Config Pind.1 = Input
Config Pind.2 = Input

Config Pind.3 = Input
Config Portd.4 = Output
Config Portd.6 = Output
Config Portd.7 = Output

Tambah Alias Pind.0 'use for counting up
Kurang Alias Pind.1 'use for counting down
Menu Alias Pind.2
Coin1 Alias Pind.3
Srcoin Alias Portd.6
Mp3 Alias Portd.7

Dim Simpan As Integer
Dim C As Integer , C1 As Integer , C2 As Integer
Dim Uang As Byte , Uang1 As Byte , Uang2 As Byte 'uang = setting coin
Dim A As Byte 'a = timer1 , b = setting lompatan , c = pembukuan
Dim Angka As Byte
Dim Angka1 As Byte
Dim Angka2 As Integer
Dim Angka3 As Integer
Dim Count As Integer , Tem1 As Integer , Tem2 As Integer ,
Dim Rib As Integer , Rat As Integer , Pul As Integer , Sat As Integer

Config Timer1 = Timer , Prescale = 8
Enable Timer1
Enable Interrupts

On Timer1 Nilai
Tcnt1 = 32768
Stop Timer1
A = 0
Reset Portd.4
Waitms 1

'===============================================================================
Atas:
Readeeprom Count , 0
If Count = -1 Then Count = 0
Readeeprom Uang , 5
If Uang = 255 Then Uang = 0

Do

Rib = Count / 1000
Tem1 = Count Mod 1000
Rat = Tem1 / 100
Tem2 = Tem1 Mod 100
Pul = Tem2 / 10
Sat = Tem2 Mod 1

If Menu = 0 Then
Waitms 200
Goto Waktu
End If

If Coin1 = 0 Then
Decr Uang
Waitms 100
If Uang = 255 Then Uang = 0

If Uang = 0 Then
Incr C
If C = 10000 Then
C = 9999
End If
Writeeeprom C , 15
Goto Bawah
End If

End If


Portb = Lookup(sat , Hitung)
Portc = &B0111
Waitms 1

Portb = Lookup(pul , Hitung)
If Rib = 0 And Rat = 0 And Pul = 0 Then
Portc = &B1111
Else
Portc = &B1011
End If
Waitms 1

Portb = Lookup(rat , Hitung)
If Rib = 0 And Rat = 0 Then
Portc = &B1111
Else
Portc = &B1101
End If
Waitms 1

Portb = Lookup(rib , Hitung)
If Rib = 0 Then
Portc = &B1111
Else
Portc = &B1110
End If
Waitms 1

Loop
'====================setting waktu==============================================
Waktu:

Do
If Menu = 0 Then
Waitms 200
Goto Coin
End If

If Tambah = 0 Then
Waitms 200
Pul = Pul + 3

If Pul = 6 Then
Pul = 0
Incr Rat
End If

If Rat = 10 Then
Rat = 0
Incr Rib
End If

If Rat = 0 And Rib = 6 Then
Rat = 0
Rib = 0
Pul = 0
Sat = 0
End If

If Rib = 2 And Rat = 4 Then
Rib = 0
Rat = 0
End If

Angka = Sat * 1
Angka1 = Pul * 10
Count = Angka1 + Angka
Angka2 = Rat * 100
Count = Angka2 + Count
Angka3 = Rib * 1000
Count = Angka3 + Count
Writeeeprom Count , 0

End If

If Kurang = 0 Then
Waitms 200
Pul = Pul - 3

If Pul = -3 Then
Pul = 3
Decr Rat
End If

If Rib = 0 And Rat = -1 And Pul = 3 Then
Rib = 0
Rat = 0
Pul = 0
End If

If Rat = -1 Then
Rat = 9
Decr Rib
End If

Angka = Sat * 1
Angka1 = Pul * 10
Count = Angka1 + Angka
Angka2 = Rat * 100
Count = Angka2 + Count
Angka3 = Rib * 1000
Count = Angka3 + Count

Writeeeprom Count , 0

End If

Portb = Lookup(sat , Hitung)
Portc = &B0111
Waitms 1

Portb = Lookup(pul , Hitung)
If Rib = 0 And Rat = 0 And Pul = 0 Then
Portc = &B1111
Else
Portc = &B1011
End If
Waitms 1

Portb = Lookup(rat , Hitung)
If Rib = 0 And Rat = 0 Then
Portc = &B1111
Else
Portc = &B1101
End If
Waitms 1

Portb = Lookup(rib , Hitung)
If Rib = 0 Then
Portc = &B1111
Else
Portc = &B1110
End If
Waitms 1

Loop
'===============================setting coin====================================
Coin:

Do
Readeeprom Uang , 5
If Menu = 0 Then
Waitms 200
Goto Pembukuan
End If

If Tambah = 0 Then
Waitms 200
Incr Uang
If Uang = 5 Then
Uang = 0
End If
Writeeeprom Uang , 5
End If

If Kurang = 0 Then
Waitms 200
Decr Uang
If Uang = 255 Then
Uang = 5
End If
Writeeeprom Uang , 5
End If

Rib = Uang / 1000
Uang1 = Uang Mod 1000
Rat = Uang1 / 100
Uang2 = Uang1 Mod 100
Pul = Uang2 / 10
Sat = Uang2 Mod 10

Portb = Lookup(sat , Hitung)
Portc = &B0111
Waitms 1

Loop
'=============================pembukuan=========================================
Pembukuan:

Do
Readeeprom C , 15
If C = -1 Then C = 0

Rib = C / 1000
C1 = C Mod 1000
Rat = C1 / 100
C2 = C1 Mod 100
Pul = C2 / 10
Sat = C2 Mod 10

Portb = Lookup(sat , Hitung)
Portc = &B0111
Waitms 1

Portb = Lookup(pul , Hitung)
If Rib = 0 And Rat = 0 And Pul = 0 Then
Portc = &B1111
Else
Portc = &B1011
End If
Waitms 1

Portb = Lookup(rat , Hitung)
If Rib = 0 And Rat = 0 Then
Portc = &B1111
Else
Portc = &B1101
End If
Waitms 1

Portb = Lookup(rib , Hitung)
If Rib = 0 Then
Portc = &B1111
Else
Portc = &B1110
End If
Waitms 1

If Menu = 0 Then
Waitms 200
Goto Atas
End If

If Tambah = 0 Then
Waitms 200
C = 0
Writeeeprom C , 15
End If

If Kurang = 0 Then
Waitms 200
C = 0
Writeeeprom C , 15
End If
Loop
'==========================start timer==========================================
Bawah:
Set Mp3
Wait 2
Set Portd.4
Start Timer1
Waitms 100
Reset Portd.4
Do

Portb = Lookup(sat , Hitung)
Portc = &B0111
Waitms 1

Portb = Lookup(pul , Hitung)
If Rib = 0 And Rat = 0 And Pul = 0 Then
Portc = &B1111
Else
Portc = &B1011
End If
Waitms 1

Portb = Lookup(rat , Hitung)
If Rib = 0 And Rat = 0 Then
Portc = &B1111
Else
Portc = &B1101
End If
Waitms 1

Portb = Lookup(rib , Hitung)
If Rib = 0 Then
Portc = &B1111
Else
Portc = &B1110
End If
Waitms 1

If Count = 0000 Then
Waitms 200
Stop Timer1
Reset Mp3
Goto Atas
End If
Loop
End
'===========================timer1 routine======================================
Nilai:
Incr A
If A = 20 Then
Decr Count
A = 0
End If

Rib = Count / 1000
Tem1 = Count Mod 1000
Rat = Tem1 / 100
Tem2 = Tem1 Mod 100
Pul = Tem2 / 10
Sat = Tem2 Mod 10

If Pul = 9 And Sat = 9 Then
Count = Count - 40
End If

Tcnt1 = 32768
Return

Hitung:
Data &B00111111 , &B00000101 , &B01011011 , &B01001111
Data &B01100101 , &B01101110 , &B01111100 , &B00000111
Data &B01111111 , &B01100111
=============================================
I already used the program but sometimes the program can get eror like the timer i set it can't save again and i must set again from first and my mp3 player suddenly can run by it self.so the program needs friend's helps to make the program perfect and not eror again Smile ..thanks for your helps.
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Mar 09, 2015 4:23 pm    Post subject: My two cents Reply with quote

Just my two cents.... Try to input $Hwstack, $swstack and $framesize. If you don't put them in your code the defaults are used and these are a bit low.

And about the SD-card, what is exatly the problem? You are using AVR-DOS I presume? Can you show your configs? And what type of SD-card are you using?

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
kiki

Bascom Member



Joined: 06 Dec 2013
Posts: 21

blank.gif
PostPosted: Tue Mar 10, 2015 6:45 am    Post subject: Reply with quote

Ooo I see, but I don't know how to put the value to $hwstack,$swstack and $framesize hahaha Smile cause I am in learning step Very Happy . And about sd card I don't know how to start/begin the program software and hardware Very Happy .but I wanna to say thanks cause bzijlstra already help me.
Back to top
View user's profile
kiki

Bascom Member



Joined: 06 Dec 2013
Posts: 21

blank.gif
PostPosted: Tue Mar 10, 2015 6:45 am    Post subject: Reply with quote

Ooo I see, but I don't know how to put the value to $hwstack,$swstack and $framesize hahaha Smile cause I am in learning step Very Happy . And about sd card I don't know how to start/begin the program software and hardware Very Happy .but I wanna to say thanks cause bzijlstra already help me.
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Mar 10, 2015 8:41 am    Post subject: stacks Reply with quote

In the top of your program you put
$hwstack = 64
$swstack = 64
$framesize = 64

This wil override the default settings.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
kiki

Bascom Member



Joined: 06 Dec 2013
Posts: 21

blank.gif
PostPosted: Tue Mar 10, 2015 12:09 pm    Post subject: Reply with quote

Oke .thanks very much sir ..I will fix my program with the value that sir give to me..
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum