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

📄 pwm.s

📁 16个单片机c语言实验程序
💻 S
字号:
	.module PWM.C
	.area text(rom, con, rel)
	.dbfile D:\实验程序\PWM输出\PWM.C
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 5
; #include <iom16v.h>
; #include <macros.h>
; 
; void port_init(void)
; {
	.dbline 6
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 7
;  DDRA  = 0x00;
	out 0x1a,R2
	.dbline 8
;  PORTB = 0x00;
	out 0x18,R2
	.dbline 9
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 10
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 11
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 12
;  PORTD = 0xff;
	ldi R24,255
	out 0x12,R24
	.dbline 13
;  DDRD  = 0xff;
	out 0x11,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 21
; }
; 
; //TIMER1 initialize - prescale:64
; // WGM: 10) PWM phz correct, TOP= ICRn
; // desired value: 1000Hz
; // actual value: 1000.000Hz (0.0%)
; void timer1_init(void)
; {
	.dbline 22
;  TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 23
;  TCNT1H = 0xFF; //setup
	ldi R24,255
	out 0x2d,R24
	.dbline 24
;  TCNT1L = 0x83;
	ldi R24,131
	out 0x2c,R24
	.dbline 25
;  OCR1AH = 0x00;
	out 0x2b,R2
	.dbline 26
;  OCR1AL = 0x65; //占空比
	ldi R24,101
	out 0x2a,R24
	.dbline 27
;  OCR1BH = 0x00;
	out 0x29,R2
	.dbline 28
;  OCR1BL = 0x10; //占空比
	ldi R24,16
	out 0x28,R24
	.dbline 29
;  ICR1H  = 0x00;
	out 0x27,R2
	.dbline 30
;  ICR1L  = 0x7D;
	ldi R24,125
	out 0x26,R24
	.dbline 31
;  TCCR1A = 0xA2;
	ldi R24,162
	out 0x2f,R24
	.dbline 32
;  TCCR1B = 0x13; //start Timer
	ldi R24,19
	out 0x2e,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 37
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 39
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 40
;  port_init();
	xcall _port_init
	.dbline 41
;  timer1_init();
	xcall _timer1_init
	.dbline 43
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 44
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 45
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 46
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fI
	.even
_main::
	.dbline -1
	.dbline 51
;  //all peripherals are now initialized
; }
; 
; main() 
; {
	.dbline 52
; init_devices();
	xcall _init_devices
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
; }

⌨️ 快捷键说明

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