Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

[ask] first project and get error

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
javanismechimol

Bascom Member



Joined: 15 Apr 2014
Posts: 9

PostPosted: Thu Nov 27, 2014 6:38 pm    Post subject: [ask] first project and get error Reply with quote

hi, this my first project using bascom avr, i have trouble with my coding. i make temperature and humidity using SHT11 and using push button to setting set point use internal eeprom. the program work very well without button, but when button coding included the program, sht11 only show once and stopped...
this my coding...

Code:

'----------------------------------------------------------------------------------
$regfile = "m16def.dat"                                    
$crystal = 8000000                                          
$baud = 9600
'----------------------------------------------------------------------------------

'-------------------------"konfigurasi LCD"-------------------------------------
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Config Lcd = 16 * 2
Cls
Lcd "Purwo Budiantoro"
Lowerline
Locate 2 , 6
Lcd "TE 2010"
Wait 2
Cursor Off Noblink
Deflcdchar 1 , 28 , 20 , 28 , 32 , 32 , 32 , 32 , 32        
'-------------------------"end of konfigurasi LCD"------------------------------
Dim Dataword As Word
Dim Command As Byte
Dim Calc As Single
Dim Calc2 As Single
Dim Rhlinear As Single
Dim Rhlintemp As Single
Dim Tempc As Single
Dim Tempf As Single
Dim Tempf0 As Single
Dim Ctr As Byte
Dim X As Word
Dim Y As Single
Dim Z As Single
Dim Suhu As String * 10
Dim Suhuf As String * 10
Dim Kelembaban As String * 10
Dim Suhu2 As String * 10
Dim Suhuf2 As String * 10
Dim Kelembaban2 As String * 10
'------------------------------
Dim I As Single
Dim Limsuhu As Single
Dim J As Single
Dim Limhum As Single

Dim Button As Single
Dim Buff As Single
Dim Memori As Single
'------------------------------
Const C1 = -4
Const C2 = 0.0405
Const C3 = -0.0000028
Const S = .01
Const H = .00008
'------------------------------

Sck1 Alias Portb.0                                          
Dataout1 Alias Portb.1                                    
Datain1 Alias Pinb.1                                        
Sck2 Alias Portb.2                                          
Dataout2 Alias Portb.3                                    
Datain2 Alias Pinb.3                                        
Kipas1 Alias Portd.0                                        
Lampu1 Alias Portd.2                                      
Blower1 Alias Portd.1                                      
Heater1 Alias Portd.3                                      

Kipas2 Alias Portd.4                                        
Lampu2 Alias Portd.6                                      
Blower2 Alias Portd.5                                      
Heater2 Alias Portd.7                                      

_menu Alias Pinc.3                                        
_up Alias Pinc.4                                            '
_down Alias Pinc.5                                        

'_menu = 1
'_up = 1
'_down = 1

'------------------------------

Declare Sub Kirim()
Declare Sub Kirim2()
Declare Sub Tombol1()
Declare Sub Tampil1()
Declare Sub Tampil2()
Declare Sub Tampil3()
Declare Sub Tombol2(byval Z As Single)
Declare Sub Tombol3(byval Z As Single)
'------------------------------
Ddrb = &B11111111
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pinb.3 = Output
Waitms 10
'------------------------------
Set Dataout1
For Ctr = 1 To 12
Set Sck1
Waitus 2
Reset Sck1
Waitus 2
Next Ctr

Set Dataout2
For Ctr = 1 To 12
Set Sck2
Waitus 2
Reset Sck2
Waitus 2
Next Ctr
'------------------------------
Ddrd = &B11111111
Portd = 0

Button = 0
Memori = 0

$eeprom
Label1:
Data 0 , 0
$data

'=== read eeprom
Readeeprom Memori , Label1
Limsuhu = Memori
Readeeprom Memori
Limhum = Memori

'=== end of read eeprom
'------------------------------


'================================ MULAI ALATNYA ========================================================


'=======================================================================================================

Do

Gosub Data_suhu , Data_suhu2

Waitms 10

   Upperline
   Lcd "suhu 1 =" ; Suhu ; " " ; Chr(1) ; "C"
   Lowerline
   Locate 2 , 3
   Lcd "Rh 1 =" ; Kelembaban ; " " ; "%"
   Wait 2
   Cls

   Upperline
   Lcd "suhu 2 =" ; Suhu2 ; " " ; Chr(1) ; "C"
   Lowerline
   Locate 2 , 3
   Lcd "Rh 2 =" ; Kelembaban2 ; " " ; "%"
   Wait 2


'========== button ========                           '
   If _menu = 0 Then
   Call Tombol1
   End If
'======end of tombol========


Loop
'-----------------------------------SHT11---------------------------------------
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Data_suhu:                                                  
Command = &B00000011
Call Kirim                                                  
Tempc = S * Dataword
Tempc = Tempc - 40

Tempf0 = Tempc * 1.8
Tempf = Tempf0 + 32
Suhu = Fusing(tempc , "#.#")
Suhuf = Fusing(tempf , "#.#")                              
Command = &B00000101
Call Kirim
Calc = C2 * Dataword
Calc2 = Dataword * Dataword
Calc2 = C3 * Calc2
Calc = Calc + C1
Rhlinear = Calc + Calc2
Calc = H * Dataword
Calc = Calc + S
Calc2 = Tempc - 25
Calc = Calc2 * Calc
Rhlintemp = Calc + Rhlinear
Kelembaban = Fusing(rhlintemp , "#.##")

   'kipas & lampu ====suhu====
   I = Limsuhu + 3
   If Tempc > I Then
     Set Kipas1
     Reset Lampu1
   End If

   I = Limsuhu - 3
   If Tempc < I Then
     Reset Kipas1
     Set Lampu1
   End If

   'blower & heater ====hum====
   J = Limhum - 4
   If Rhlintemp > J Then
     Reset Blower1
     Reset Heater1
   End If

   J = Limhum + 4
   If Rhlintemp < J Then
     Set Blower1
     Set Heater1
   End If

   Waitms 10


'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Data_suhu2:                                                
Command = &B00000011
Call Kirim2                                                
Tempc = S * Dataword
Tempc = Tempc - 40

Tempf0 = Tempc * 1.8
Tempf = Tempf0 + 32
Suhu2 = Fusing(tempc , "#.#")
Suhuf2 = Fusing(tempf , "#.#")                              
Command = &B00000101
Call Kirim2
Calc = C2 * Dataword
Calc2 = Dataword * Dataword
Calc2 = C3 * Calc2
Calc = Calc + C1
Rhlinear = Calc + Calc2
Calc = H * Dataword
Calc = Calc + S
Calc2 = Tempc - 25
Calc = Calc2 * Calc
Rhlintemp = Calc + Rhlinear
Kelembaban2 = Fusing(rhlintemp , "#.##")

   'kipas & lampu ====suhu====
   I = Limsuhu + 3
   If Tempc > I Then
     Set Kipas1
     Reset Lampu1
   End If

   I = Limsuhu - 3
   If Tempc < I Then
     Reset Kipas1
     Set Lampu1
   End If

   'blower & heater ====hum====
   J = Limhum - 4
   If Rhlintemp > J Then
     Reset Blower1
     Reset Heater1
   End If

   J = Limhum + 4
   If Rhlintemp < J Then
     Set Blower1
     Set Heater1
   End If

   Waitms 10


Return
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sub Kirim()
Local Datavalue As Word
Local Databyte As Byte
Set Sck1
Reset Dataout1
Reset Sck1
Set Sck1
Set Dataout1
Reset Sck1
Shiftout Dataout1 , Sck1 , Command , 1
Ddrb = &B11111101
Config Pinb.1 = Input
Set Sck1
Reset Sck1
Waitus 10
Bitwait Pinb.1 , Reset
Shiftin Datain1 , Sck1 , Databyte , 1
Datavalue = Databyte
Ddrb = &B11111111
Config Pinb.1 = Output
Reset Dataout1
Set Sck1
Reset Sck1
Ddrb = &B11111101
Config Pinb.1 = Input
Shiftin Datain1 , Sck1 , Databyte , 1
Shift Datavalue , Left , 8
Datavalue = Datavalue Or Databyte
Dataword = Datavalue
Ddrb = &B11111111
Config Pinb.1 = Output
Reset Dataout1
Set Sck1
Reset Sck1
Ddrb = &B11111101
Config Pinb.1 = Input
Shiftin Datain1 , Sck1 , Databyte , 1
Ddrb = &B11111111
Config Pinb.1 = Output
Set Dataout1
Set Sck1
Reset Sck1
End Sub
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sub Kirim2()
Local Datavalue As Word
Local Databyte As Byte
Set Sck2
Reset Dataout2
Reset Sck2
Set Sck2
Set Dataout2
Reset Sck2
Shiftout Dataout2 , Sck2 , Command , 1
Ddrb = &B11111101
Config Pinb.3 = Input
Set Sck2
Reset Sck2
Waitus 10
Bitwait Pinb.3 , Reset
Shiftin Datain2 , Sck2 , Databyte , 1
Datavalue = Databyte
Ddrb = &B11111111
Config Pinb.2 = Output
Reset Dataout2
Set Sck2
Reset Sck2
Ddrb = &B11111101
Config Pinb.3 = Input
Shiftin Datain2 , Sck2 , Databyte , 1
Shift Datavalue , Left , 8
Datavalue = Datavalue Or Databyte
Dataword = Datavalue
Ddrb = &B11111111
Config Pinb.3 = Output
Reset Dataout2
Set Sck2
Reset Sck2
Ddrb = &B11111101
Config Pinb.3 = Input
Shiftin Datain2 , Sck2 , Databyte , 1
Ddrb = &B11111111
Config Pinb.3 = Output
Set Dataout2
Set Sck2
Reset Sck2
End Sub
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'-----------------------------------END OF SHT11--------------------------------

Sub Tombol1()
   Do
     If _menu = 0 Then
        Do
        Waitms 10
        Loop Until _menu = 1
        Button = Button + 1
     End If

     Select Case Button
        Case 1 : Call Tampil1()
        Case 2 : Call Tampil2()
     End Select
   Loop Until Button > 2
   Button = 0
   Call Tampil3()
End Sub

Sub Tampil1()
   '===tampil1===
   Buff = Limsuhu
   Call Tombol2(limsuhu)
   Call Tombol3(limsuhu)
   Limsuhu = Buff

   Cls
   Lcd "set suhu 1"
   Lowerline
   Lcd Limsuhu
   Waitms 100
   '====================
End Sub

Sub Tampil2()
   '===tampil2===
   Buff = Limhum
   Call Tombol2(limhum)
   Call Tombol3(limhum)
   Limhum = Buff

   Cls
   Lcd "set hum 1"
   Lowerline
   Lcd Limhum
   Waitms 100
   '====================
End Sub

Sub Tampil3()
   '=========
   Cls
   Lcd "saving . . ."
   Waitms 200
   '=== save eeprom
   Writeeeprom Limsuhu , Label1
   Writeeeprom Limhum
   '=== end of save eeprom
   Cls
   Lcd "saved"
   Wait 1
   '=========
End Sub

Sub Tombol2(byval Z As Single)
   If _up = 0 Then
      Do
      Waitms 50
      Loop Until _up = 1
      '===tombol up
      Z = Z + 1
      Buff = Z
      '===tombol up
   End If
End Sub

Sub Tombol3(byval Z As Single)
   If _down = 0 Then
      Do
      Waitms 50
      Loop Until _down = 1
      '===tombol down
      Z = Z - 1
      Buff = Z
      '===tombol down
   End If
End Sub
End
 


Code:

this the problem and how to fix it...

'========== button ========                           '
   If _menu = 0 Then
   Call Tombol1
   End If
'======end of tombol========
 
[/code]

(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.7 )
Back to top
View user's profile
bzijlstra

Bascom Ambassador



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

netherlands.gif
PostPosted: Thu Nov 27, 2014 6:59 pm    Post subject: hw en swstacks Reply with quote

Check $hwstack, $swstack and $framesize. They are now the default settings of your bascom-AVR configuration.

Try
$hwstack = 64
$swstack = 64
$framesize = 64

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

Bascom Member



Joined: 10 Feb 2014
Posts: 66
Location: Melbourne

australia.gif
PostPosted: Thu Nov 27, 2014 9:59 pm    Post subject: Reply with quote

I don't know, but I reckon this section should be re-written.
Seems very complicated for what it's actually trying to accomplish.

Code:
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'-----------------------------------END OF SHT11--------------------------------

Sub Tombol1()
    Do
      If _menu = 0 Then
         Do
         Waitms 10
         Loop Until _menu = 1
         Button = Button + 1
      End If

      Select Case Button
         Case 1 : Call Tampil1()
         Case 2 : Call Tampil2()
      End Select
    Loop Until Button > 2
    Button = 0
    Call Tampil3()
End Sub

Sub Tampil1()
    '===tampil1===
    Buff = Limsuhu
    Call Tombol2(limsuhu)
    Call Tombol3(limsuhu)
    Limsuhu = Buff

    Cls
    Lcd "set suhu 1"
    Lowerline
    Lcd Limsuhu
    Waitms 100
    '====================
End Sub

Sub Tampil2()
    '===tampil2===
    Buff = Limhum
    Call Tombol2(limhum)
    Call Tombol3(limhum)
    Limhum = Buff

    Cls
    Lcd "set hum 1"
    Lowerline
    Lcd Limhum
    Waitms 100
    '====================
End Sub

Sub Tampil3()
    '=========
    Cls
    Lcd "saving . . ."
    Waitms 200
    '=== save eeprom
    Writeeeprom Limsuhu , Label1
    Writeeeprom Limhum
    '=== end of save eeprom
    Cls
    Lcd "saved"
    Wait 1
    '=========
End Sub

Sub Tombol2(byval Z As Single)
    If _up = 0 Then
       Do
       Waitms 50
       Loop Until _up = 1
       '===tombol up
       Z = Z + 1
       Buff = Z
       '===tombol up
    End If
End Sub

Sub Tombol3(byval Z As Single)
    If _down = 0 Then
       Do
       Waitms 50
       Loop Until _down = 1
       '===tombol down
       Z = Z - 1
       Buff = Z
       '===tombol down
    End If
End Sub
End
 
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 699

poland.gif
PostPosted: Thu Nov 27, 2014 11:14 pm    Post subject: Reply with quote

Maybe I`m wrong but I can`t find pull up`s for PINC.3 (_menu switch) Isn`t the pin allways LOW and program wait for Button relase??
You have commented " _menu = 1" but this change nothing because You must PORTC.3 = 1 not PINC.3 = 1 and after Alias You cant Set _menu = 1 because it is PIN not PORT. If You fix that then You can improve (I think) code with this : If You add alias to DDR port then You can easly switch betwen Input - Output calling alias like this


Code:

Config Portb.1 = Input
Data_pin Alias Pinb.1
Data_direction Alias DDRB.1


'then in code You can call
Data_direction = 1    'Pin is output
Data_direction = 0    'Pin is input
 
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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