 |
Forumas » Elektronika žaliems » AVR pradedanciam
|
Jūs negalite rašyti naujų pranešimų į šį forumą Jūs negalite atsakinėti į pranešimus šiame forume Jūs negalite redaguoti savo pranešimų šiame forume Jūs negalite ištrinti savo pranešimų šiame forume Jūs negalite dalyvauti apklausose šiame forume
|
|
|
Puslapis 2 iš 2 Pereiti prie Atgal 1, 2 |
|
 |
 |
 |
AVR pradedanciam |
Parašytas: 2009 11 19, 20:17 |
|
|
|
|
| caca rašo: |
| negaliu atidaryti nuorodos... Meistryste tokia: dabar isivaizduoju yra ciklas, kuriame yra bitas 0, pauze, bitas 1, pauze ir t.t. T.b. bitas 0, trumpa pauze, cikliukas paverberavimui ir vel 0 ir vel paverberavimas. |
Gal kolegos neįsižeis, kad visą asm įkelsiu čia. Įsivaizduoti tai įsivaizduoju, bet nerandu kur tai yra realizuota.
| Kodas: |
' Charge Controller
' Ver 2006C
' www.thebackshed.com
SYMBOL Volt = b6 ; Measured Battery Volts
SYMBOL CVolt = b7 ; Charging Voltage Level
SYMBOL LVolt = b8 Start:
SYMBOL Amp = b4 ; Measured Battery Amps ; Load Voltage Level
SYMBOL LBatt = b9 ; Low Battery Alarm Level
EEPROM 0,( $33 )
EEPROM 1,( $32 )
EEPROM 2,( $28 )
EEPROM 3,( $0C )
EEPROM 4,( $06 )
EEPROM 5,( $01 )
EEPROM 6,("V ")
EEPROM 9,("A ")
EEPROM 16,("CHARGING")
EEPROM 24,("ON LOAD ")
EEPROM 32,("Set Load Volts")
EEPROM 46,("Set Charge Volts")
EEPROM 62,("Forced Load")
EEPROM 73,("Forced Charge")
EEPROM 86,("LOW BATT")
EEPROM 94,("Set Low Batt")
read 120,CVolt ' read in Charge volt level saved in eeprom
read 121,LVolt ' read in Load volt level saved in eeprom
read 122,LBatt ' read in Low Battery volt level saved in eeprom
FOR b11 = 0 TO 5 ' Initialise the LCD display
READ b11,b12
pause 15
GOSUB SendCmdByte
NEXT
b12=1 ' set controler to charging mode
Gosub SendCmdByte
b12 = 192
GOSUB SendCmdByte
FOR b11 = 16 TO 23
READ b11,b12
GOSUB SendDataByte
NEXT
gosub Beep
low portc 5
high portc 4
if LVolt=0 then DefaultVolt
goto main
DefaultVolt:
' This routine sets some default voltages if there are no preset values in the eeprom
LVolt=40 ' Set default load voltage to 14.0
write 121,LVolt ' save to eeprom
CVolt=22 ' Set default charge voltage to 12.2
write 120,CVolt ' save to eeprom
LBatt=12 ' Set default low batt voltage to 11.2
write 122,LBatt ' save to eeprom
' ########## Main battery regulating routine
Main:
nap 10 ' Have a little sleep to save some power.
gosub GetValues
if pin1 = 1 then menu1 ' Is menu button pressed?
if pin6 = 0 then OnLoad ' Is Forced Load switch on?
if pin7 = 0 then OnCharge ' Is Forced Charge switch on?
sertxd("<V=", #volt, ",A=", #Amp, ">") ' send the data back via the serial port to the PC for logging.
B5 = Volt
b12 = 2
Gosub SendCmdByte
gosub DisplayVolt
FOR b11 = 6 TO 8 ' Display "V"
READ b11,b12
GOSUB SendDataByte
NEXT
gosub DisplayAmp
FOR b11 = 9 TO 11 ' Display "A"
READ b11,b12
GOSUB SendDataByte
NEXT
if Volt<LBatt then LowBattAlarm 'Low volts, sound alarm
if Volt>LVolt then SwitchToLoad 'Battery fully charged, switch windmill to Load.
if Volt<CVolt then SwitchToCharging 'Battery b11ting low, switch windmill to Battery.
goto main
' ########## Send info to the screen routine.
SendCmdByte:
b13 = %00000000 ; Send to Command register
SendDataByte:
pins = b12 & %11110000 | b13 ; Put MSB out first
PULSOUT 3,1 ; Give a 10uS pulse on E
pins = b12 * %00010000 | b13 ; Put LSB out second
PULSOUT 3,1 ; Give a 10uS pulse on E
b13 = %00000100 ; Send to Data register next
RETURN
' ########## Read in values for Volts and Amps
GetValues:
readadc10 0,w0 ' read in volts
' trim down to a range of 100 to 355.
' ie if it was less than 100, it bcomes 100.
' if it was over 355, it becomes 355.
' this gives us a voltage range of 10.0 to 35.5.
let w0=w0 min 100
let w0=w0 max 355
' As we can only use bytes, we take off 100 to give us a range of 0 to 255.
' 0 = 10 volts, 255 = 35.5 volts
Volt = w0 - 100
readadc10 1, w0 ' Reads in Amps
let w0=w0 min 300
let w0=w0 max 555
' As above, but this time 0=-128 amps, 128=0 amps, 255=128 amps.
' remember we want to read plus and minus amps
Amp = w0-300
Return
' ########## Low Battery Voltage alarm.
LowBattAlarm:
gosub Beep ' Make a noise!
low portc 5 ' Make sure controller is in charge mode
high portc 4
b12 = 192 ' move to 2nd line on screen
GOSUB SendCmdByte
FOR b11 = 86 TO 93
READ b11,b12
GOSUB SendDataByte ' Display "Low Batt"
NEXT
nap 10 ' Have a little sleep.
goto Main
' ########## Swift from Charging to Load and visa-versa
SwitchToLoad:
b12 = 192 ' move to 2nd line on screen
GOSUB SendCmdByte
FOR b11 = 24 TO 31
READ b11,b12
GOSUB SendDataByte ' Display "On Load"
NEXT
Low portc 4 ' Turn off MOSFETS to battery.
High portc 5 ' Turn on MOSFETS to dummy load
goto Main
SwitchToCharging:
b12 = 192 ' move to 2nd line on screen
GOSUB SendCmdByte
FOR b11 = 16 TO 23
READ b11,b12
GOSUB SendDataByte ' Display "Charging"
NEXT
low portc 5 ' Turn off MOSFETS to dummy load
high portc 4 ' Turn on MOSFETS to battery.
goto Main
' ########## Display Volts and Amps routine
DisplayVoltLine2:
b12 = 192
GOSUB SendCmdByte
DisplayVolt: ' the routine breaks up the voltage into individual numbers and displays each in turn
b10=b5/100
b12=b10+49
GOSUB SendDataByte
b10=b10*100
b5=b5-b10
b10=b5/10
b12=b10+48
GOSUB SendDataByte
b12 = 46
Gosub SendDataByte
b10=b10*10
b5=b5-b10
b10=b5
b12=b10+48
GOSUB SendDataByte
Return
DisplayAmp: ' Same as above, but adds the - and + symbols for current
If Amp>128 then pamp
if Amp<128 then namp
if Amp=128 then oamp
goto d1
pamp:
Amp=Amp-128
goto d1
namp:
b12=45
GOSUB SendDataByte
Amp=128-Amp
goto d1
oamp:
Amp=0
goto d1
d1:
b5=amp
b10=b5/100
b12=b10+48
GOSUB SendDataByte
b10=b10*100
b5=b5-b10
b10=b5/10
b12=b10+48
GOSUB SendDataByte
b12 = 46
Gosub SendDataByte
b10=b10*10
b5=b5-b10
b10=b5
b12=b10+48
GOSUB SendDataByte
Return
' ######## Setup menu routine
Menu1: 'Set the Charge Voltage "CVolt"
GOSUB Beep
pause 500
b12 = 1
GOSUB SendCmdByte
b12 = 128
GOSUB SendCmdByte
FOR b11 = 46 TO 61 'Display "Set Charge Volts"
READ b11,b12
GOSUB SendDataByte
NEXT
b5 = CVolt
gosub DisplayVoltLine2
Menu1a:
pause 100
if pin1 = 1 then Menu2
if pin2 = 1 then UpChargeVolt
if pin3 = 1 then DownChargeVolt
goto Menu1a
UpChargeVolt:
CVolt = CVolt + 1
b5 = CVolt
gosub DisplayVoltLine2
write 120,CVolt 'save in eeprom
goto Menu1a
DownChargeVolt:
CVolt = CVolt - 1
b5 = CVolt
gosub DisplayVoltLine2
write 120,CVolt 'save in eeprom
goto Menu1a
Menu2: 'Set the Load Voltage "LVolt"
GOSUB Beep
pause 500
b12 = 1
GOSUB SendCmdByte
b12 = 128
GOSUB SendCmdByte
FOR b11 = 32 TO 45 'Display "Set Load Volts"
READ b11,b12
GOSUB SendDataByte
NEXT
b5 = LVolt
gosub DisplayVoltLine2
Menu2a:
pause 100
if pin1 = 1 then Menu3
if pin2 = 1 then UpLoadVolt
if pin3 = 1 then DownLoadVolt
goto Menu2a
UpLoadVolt:
LVolt = LVolt + 1
b5 = LVolt
gosub DisplayVoltLine2
write 121,LVolt 'save in eeprom
goto Menu2a
DownLoadVolt:
LVolt = LVolt - 1
b5 = LVolt
gosub DisplayVoltLine2
write 121,LVolt 'save in eeprom
goto Menu2a
Menu3: 'Set the Low Batt alarm voltage "LBatt"
GOSUB Beep
pause 500
b12 = 1
GOSUB SendCmdByte
b12 = 128
GOSUB SendCmdByte
FOR b11 = 94 TO 105 'Display "Set Low Batt"
READ b11,b12
GOSUB SendDataByte
NEXT
b5 = LBatt
gosub DisplayVoltLine2
Menu3a:
pause 100
if pin1 = 1 then Start
if pin2 = 1 then UpLBattVolt
if pin3 = 1 then DownLBattVolt
goto Menu3a
UpLBattVolt:
LBatt = LBatt + 1
b5 = LBatt
gosub DisplayVoltLine2
write 122,LBatt 'save in eeprom
goto Menu3a
DownLBattVolt:
LBatt = LBatt - 1
b5 = LBatt
gosub DisplayVoltLine2
write 122,LBatt 'save in eeprom
goto Menu3a
' ########## Forced Charge / Load routines.
' The following routines work the same way as the "Main" loop, except that the controler state is fixed.
OnLoad:
gosub beep
OnLoad1:
Low portc 4
High portc 5
nap 10
gosub GetValues
if pin6 = 1 then Start
sertxd("<V=", #volt, ",A=", #Amp, ">")
B5 = Volt
b12 = 2
Gosub SendCmdByte
gosub DisplayVolt
FOR b11 = 6 TO 8
READ b11,b12
GOSUB SendDataByte
NEXT
gosub DisplayAmp
FOR b11 = 9 TO 11
READ b11,b12
GOSUB SendDataByte
NEXT
' Display "Forced Load"
b12 = 192
GOSUB SendCmdByte
FOR b11 = 62 TO 72
READ b11,b12
GOSUB SendDataByte
NEXT
Goto OnLoad1
OnCharge:
gosub beep
OnCharge1:
low portc 5
high portc 4
nap 10
gosub GetValues
if pin7 = 1 then Start
sertxd("<V=", #volt, ",A=", #Amp, ">")
B5 = Volt
b12 = 2
Gosub SendCmdByte
gosub DisplayVolt
FOR b11 = 6 TO 8
READ b11,b12
GOSUB SendDataByte
NEXT
gosub DisplayAmp
FOR b11 = 9 TO 11
READ b11,b12
GOSUB SendDataByte
NEXT
' Display "Forced Charge"
b12 = 192
GOSUB SendCmdByte
FOR b11 = 73 TO 85
READ b11,b12
GOSUB SendDataByte
NEXT
goto OnCharge1
Beep: 'Make a noise
for b3=1 to 8
high portc 0
pause 1
low portc 0
pause 1
next
return
|
|
|
|
|
|
|
 |
 |
AVR pradedanciam |
Parašytas: 2009 11 19, 20:25 |
|
|
|
|
Ar ne ši dalis generuoja garsą?
| Kodas: |
SendCmdByte:
b13 = %00000000 ; Send to Command register
SendDataByte:
pins = b12 & %11110000 | b13 ; Put MSB out first
PULSOUT 3,1 ; Give a 10uS pulse on E
pins = b12 * %00010000 | b13 ; Put LSB out second
PULSOUT 3,1 ; Give a 10uS pulse on E
b13 = %00000100 ; Send to Data register next
RETURN |
|
|
|
|
|
|
 |
AVR pradedanciam |
Parašytas: 2009 11 19, 21:05 |
|
|
|
|
gal sita
| Kodas: |
Beep: 'Make a noise
for b3=1 to 8
high portc 0
pause 1
low portc 0
pause 1
next
return |
|
|
|
|
|
|
 |
AVR pradedanciam |
Parašytas: 2009 11 19, 23:05 |
|
|
|
|
Taip, dėkui, jau ir pats radau, tik kaip padaryti aukštesnį garsą, noriu išgauti svirplį, nors ir pause surašau nulius, vis vien peržemas. Čia biški darašiau, gal 50 derinių išbandžiau, negaunu to, ko noriu.
| Kodas: |
Beep: 'Make a noise
for b3=1 to 8
high portc 0
pause 0
low portc 0
pause 2
high portc 0
pause 4
low portc 0
pause 3
high portc 0
pause 6
low portc 0
pause 0
high portc 0
pause 2
low portc 0
pause 3
next
return |
Tas daiktas dirbs kieme, jei naktį ims cirpti kaip svirplys, tai kaimynai nesinervins, o aš žinosiu kas nutiko. |
|
|
|
|
|
 |
AVR pradedanciam |
Parašytas: 2009 11 20, 10:53 |
|
|
|
|
Ačiū už pagalbą, padariau kuklų garsą, kuris nelabai ką nervins:
| Kodas: |
Beep: 'Make a noise
for b3=000101 to 8
high portc 0
low portc 0
next
return |
|
|
|
|
|
|
|
 |
Google paieška forume |
|
|
 |
Naujos temos forume |
|
 |
FS25 Tractors
Farming Simulator 25 Mods,
FS25 Maps,
FS25 Trucks |
 |
ETS2 Mods
ETS2 Trucks,
ETS2 Bus,
Euro Truck Simulator 2 Mods
|
 |
FS22 Tractors
Farming Simulator 22 Mods,
FS22 Maps,
FS25 Mods |
 |
Dantų protezavimas
All on 4 implantai,
Endodontija mikroskopu,
Dantų implantacija |
 |
FS25 Mods
FS25 Maps,
FS25 Cheats,
FS25 Install Mods |
 |
FS25 Mods
Farming Simulator 25 Mods,
FS25 Maps |
 |
ATS Trailers
American Truck Simulator Mods,
ATS Trucks,
ATS Maps |
 |
RDR2 Mods
Euro Truck Simulator 2 Mods,
WOT Mods,
RDR2 Maps |
|