⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oc1ab输出pwm.s

📁 ICC mega8例子
💻 S
字号:
	.module OC1AB输出PWM.c
	.area text(rom, con, rel)
	.dbfile E:\xiaozhiyong2009\设计资料\项目设计\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)
; 入口参数:A,B的占空比
; 出口参数:
; *************************************/
; 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;//设置TCNT1的初值
	clr R3
	out 0x2d,R3
	out 0x2c,R2
	.dbline 45
;  OCR1A=x;//设置OC1A的初值
	out 0x2b,R17
	out 0x2a,R16
	.dbline 46
;  OCR1B=y;//设置OC1B的初值
	out 0x29,R19
	out 0x28,R18
	.dbline 47
;  ICR1=0xff;//设置ICR的初值
	ldi R24,255
	ldi R25,0
	out 0x27,R25
	out 0x26,R24
	.dbline 50
;  //系统时钟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
; }
; //调节占空比
; 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
; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -