I just dug out some code I wrote about 10 years ago to control an audio system with an AT90S2313 and started rewriting it to run on ATmega8A with 12MHz crystal. I set the clock config fusebits to CKOPT=0, clock select to 101111, using a USBasp programmer. All seemed fine.
I then downloaded my compiled code and it ran, but very slowly. Checked the fusebits - the clock config fusebits were back to defaults. I set them properly again, program ran fine, decoded RC5 correctly.
Tweaked the code, compiled, downloaded - back to 1MHz internal clock. I've tried different programmer clocks and it's the same using my old STK200/300 clone programmer.
BASCOM is 2.0.7.5 Demo on Win XP SP3. I've just done some mods to some code on a Tiny2313 with the same setup and had no trouble at all.
Here's the code so far. What silly mistake have I made?
[code:1:90c5fccbd4]
' Audio Preamp Controller 2
' ATmega8A version
' Colin McKie
$regfile = "m8adef.dat"
$crystal = 12000000 '12 MHz
Dim Gain As String * 8 'Display string
Dim Gain_raw As Integer 'optical pulse counter
Dim Gain_db As Integer 'counter value converted to db
Dim Gain_max As Byte 'Maximum gain allowed
Gain_max = 212 'Set to 10db
Dim Gain_out As Byte , Gain_right As Byte , Gain_left As Byte, 'Control value to PGA2310
Dim Balance As Integer
Balance = 0
Dim Mute As Bit 'Mute flag
Dim Rc_address As Byte , Rc_command As Byte
Const Step_db = 5
Const Min_db = -960
Config Portb = Output
Config Portd = Input
Portd = 255 'enable Portd pullup's
Config Portc = Output
Config Rc5 = Pind.0 , Wait = 2000 'Set remote input pin
Config Lcdbus = 4
Config Lcd = 20x2
Config Lcdpin = Pin , Db4 = Pb.2 , Db5 = Pb.3 , Db6 = Pb.4 , Db7 = Pb.5 , E = Pb.1 , Rs = Pb.0
Cls
Cursor Off
Phase_a Alias Pind.2 'INT0 also connected to Pind.3 = INT1
Phase_b Alias Pind.4
Data_out Alias Pinc.4 'Data out to PGA2310
Data_clock Alias Pinc.5 'Data clock to PGA2310
Data_enable Alias Pinc.3 'Chip select to PGA2310
' Set Interrupt logic
Mcucr = &B00001011 'set interrupt edges
On Int0 Phase_a_edge 'ISR on rising edge
On Int1 Phase_a_edge 'ISR on falling edge
Enable Int0
Enable Int1
Enable Interrupts
' Initialization
Lcd "Control Rev.2.0"
Mute = 1
Waitms 2000
Cls
Mute = 0
Gain_raw = 132 'Set initial gain to -30db
' Main program loop
Do
If Gain_raw > 0 Then
Gain_db = Gain_raw * Step_db 'convert to db x10
Gain_db = Gain_db + Min_db
Gain = Str(gain_db) 'Make string
Gain = Format(gain , " +0.0") 'format without leading zeros
Else
Gain = "Muted"
End If
Locate 1 , 7
Lcd " "
Locate 1 , 1
Lcd "Comm: " ; Rc_command 'Display remote command
Locate 2 , 1
Lcd "Gain " ; Gain ; " db" 'Display gain
Gosub Send_gain
Gosub Get_remote
Waitms 200 'Slow loop down
Loop
End
' Encoder Interrupt Routine
Phase_a_edge: 'Interrupt on rising and falling edge
If Phase_b <> Phase_a Then 'test phase B
Decr Gain_raw 'CCW
If Gain_raw < 0 Then Gain_raw = 0 'Limit attenuation
Else
Incr Gain_raw 'CW
If Gain_raw > Gain_max Then Gain_raw = Gain_max 'Limit gain
End If
Return
' Send gain setting
Send_gain:
If Mute = 1 Then
Gain_out = 0
Else
Gain_out = Gain_raw
Gain_right = Gain_out + Balance
Gain_left = Gain_out - Balance
End If
Reset Data_enable
Shiftout Data_out , Data_clock , Gain_right , 1 'Send R channel data
Shiftout Data_out , Data_clock , Gain_left , 1 'Send L channel data
Set Data_enable
Return
' Get RC5 signal
Get_remote:
Getrc5(rc_address , Rc_command) 'Get RC5 command
Rc_command = Rc_command And &B01111111
Return
[/code:1:90c5fccbd4]
[b:90c5fccbd4][color=red:90c5fccbd4](BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.6 )[/b:90c5fccbd4][/color:90c5fccbd4]
↧