?? oc1ab輸出pwm.s
字號(hào):
.module OC1AB輸出PWM.c
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\設(shè)計(jì)資料\項(xiàng)目設(shè)計(jì)\ICCAVR_mega8_C\ICCAVR_mega8_OC1AB輸出PWM\OC1AB輸出PWM.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 9
; //ICC-AVR application builder : 2009-3-11 13:52:41
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 10
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 11
; DDRB = 0x00;
out 0x17,R2
.dbline 12
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 13
; DDRC = 0x00;
out 0x14,R2
.dbline 14
; PORTD = 0x00;
out 0x12,R2
.dbline 15
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 20
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 22
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 23
; port_init();
rcall _port_init
.dbline 25
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 26
; GICR = 0x00;
out 0x3b,R2
.dbline 27
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 28
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_timer1_PWM _init_timer1_PWM fV
; y -> R18,R19
; x -> R16,R17
.even
_init_timer1_PWM::
.dbline -1
.dbline 41
; //all peripherals are now initialized
; }
;
; /************************************
; 用 途:用TC1輸出PWM
; Taget :mega8
; crystal :8M
; 介 紹:PB1(OC1A),PB2(OC1B)
; 入口參數(shù):A,B的占空比
; 出口參數(shù):
; *************************************/
; void init_timer1_PWM(unsigned int x,unsigned int y)
; {
.dbline 42
; DDRB|=(1<<PB1)|(1<<PB2);
in R24,0x17
ori R24,6
out 0x17,R24
.dbline 43
; TCCR1B=0x0;//先停止TC1
clr R2
out 0x2e,R2
.dbline 44
; TCNT1=0;//設(shè)置TCNT1的初值
clr R3
out 0x2d,R3
out 0x2c,R2
.dbline 45
; OCR1A=x;//設(shè)置OC1A的初值
out 0x2b,R17
out 0x2a,R16
.dbline 46
; OCR1B=y;//設(shè)置OC1B的初值
out 0x29,R19
out 0x28,R18
.dbline 47
; ICR1=0xff;//設(shè)置ICR的初值
ldi R24,255
ldi R25,0
out 0x27,R25
out 0x26,R24
.dbline 50
; //系統(tǒng)時(shí)鐘64分頻CS1[2、0]=0x03
; //COM1A[1-0]=0x00,COM1B[1-0]=0x02
; TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
in R24,0x2f
ori R24,162
out 0x2f,R24
.dbline 51
; TCCR1B|=(1<<WGM13)|(1<<CS11)|(1<<CS10);//Starttimer
in R24,0x2e
ori R24,19
out 0x2e,R24
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r y 18 i
.dbsym r x 16 i
.dbend
.dbfunc e timer1_PWM _timer1_PWM fV
; y -> R18,R19
; x -> R16,R17
.even
_timer1_PWM::
.dbline -1
.dbline 55
; }
; //調(diào)節(jié)占空比
; void timer1_PWM(unsigned int x,unsigned int y)
; {
.dbline 56
; OCR1A=x;
out 0x2b,R17
out 0x2a,R16
.dbline 57
; OCR1B=y;
out 0x29,R19
out 0x28,R18
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbsym r y 18 i
.dbsym r x 16 i
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 61
; }
;
; void main()
; {
.dbline 62
; port_init();
rcall _port_init
.dbline 63
; init_devices();
rcall _init_devices
.dbline 65
;
; init_timer1_PWM(100,200);
ldi R18,200
ldi R19,0
ldi R16,100
ldi R17,0
rcall _init_timer1_PWM
rjmp L7
L6:
.dbline 67
; while(1)
; {
.dbline 68
; PORTB=0xff;
ldi R24,255
out 0x18,R24
.dbline 69
; }
L7:
.dbline 66
rjmp L6
X0:
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -