Czy może ktoś skompilować ten kod mieszanka asemblera z C i umieścić tu wsad (HEX)
Niby udało mi się to skompilować w AVR studio Ale program niby dział jak powinien, ale PWM ma max 0.6Hz
;*********************************************************************
; Program : t13pwm.asm
; Description : Tiny13 Fast PWM and ADC Fan Controller
; Last Updated : 15 December 2008
; Author : RWB
; IDE/Compiler : Atmel AVR Studio 4.14
; Programmer : AvrOspII v5.47 from Mike Henning
; : AVRJazz Tiny2313 Board
;*********************************************************************
.include "tn13def.inc"
; The Tiny13 Default Frequency Clock
.equ F_CPU = 9600000
.cseg
; Start on the flash ram's address 0
.org 0
main: ldi R24,RAMEND ; Initial Stack Pointer
out SPL,R24 ; SP = RAMEND
; Initial I/O
ldi R16,0b00000011 ; Set PB0=Output, PB1=Output, PB2=Input, PB3=Input, PB4=Output
out DDRB,R16 ; DDRB=0x03
; Initial ADC
ldi R16,0b10000110
out ADCSRA,R16 ; Turn On the ADC, with prescaler 64
ldi R16,0b00000000
out ADCSRB,R16 ; Free running mode
ldi R16,0b01100001
out ADMUX,R16 ; Internal Reference 1.1 Volt,Left Adjust, Channel: PB2 (ADC1)
ldi R16,0b00000100 ; Disable Digital Input on PB2
out DIDR0,R16
; Initial PWM
ldi R16,0b10000011
out TCCR0A,R16 ; Fast PWM Mode, Clear on OC0A
ldi R16,0b00000100
out TCCR0B,R16 ; Used fclk/256 prescaller
; Initial the Button Flag and PORTB
ldi R17,0 ; Initial Button Flag
out PORTB,R17
lb_00: sbic PINB,PB3 ; if (PB3 == 0)
rjmp lb_20 ; else goto lb_20
ldi R19,5 ; Use delay for simple debounce
rcall delay_func
sbic PINB,PB3 ; if (PB3 == 0), read again
rjmp lb_20 ; else goto lb_20
cpi R17,1 ; Process if button pressed
brne lb_10 ; if (R17 != 1) goto lb_10
ldi R17,0 ; else R17=0
ldi R16,0 ; Disable PWM Clock
out TCCR0A,R16 ; TCCR0A = 0
out TCCR0B,R16 ; TCCR0B = 0
cbi PORTB,PB0 ; Turn off Motor
cbi PORTB,PB1 ; Turn off LED
rjmp lb_20
lb_10: ldi R17,1 ; R17=1
ldi R16,0b10000011
out TCCR0A,R16 ; Fast PWM Mode, Clear on OCR0A
ldi R16,0b00000100
out TCCR0B,R16 ; Used fclk/256 prescaller
sbi PORTB,PB1 ; Turn on LED
lb_20: cpi R17,1 ; if (R17 != 1)
brne lb_40 ; goto lb_50
;
sbi ADCSRA,ADSC ; Start ADC conversion
lb_30: sbic ADCSRA,ADSC ; while (ADCSRA & (1<<ADSC))
rjmp lb_30
in R16,ADCH ; Read the result Ignore the last 2 bits in ADCL
out OCR0A,R16 ; OCR0A = R16
cbi PORTB,PB1 ; Turn off LED
mov R19,R16
rcall delay_func ; Call Delay Function Parameter R19
sbi PORTB,PB1 ; Turn on LED
lb_40: mov R19,R16
rcall delay_func ; Call Delay Function Parameter R19
rjmp lb_00
; Simple Delay Function
delay_func:
delay0: ldi R20,25 ; R20 = 25
delay1: ldi R21,255 ; R21 = 255
delay2: dec R21 ; Decrease R21
brne delay2 ; if (R20 != 0) goto delay2 label
dec R20 ; Decrease R20
brne delay1 ; if (R20 != 0) goto delay1 label
dec R19 ; Decrease R19
brne delay0 ; if (R19 != 0) goto delay0 label
ret ; Return to the caller
.exitNiby udało mi się to skompilować w AVR studio Ale program niby dział jak powinien, ale PWM ma max 0.6Hz
