📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.even
_port_init::
; /*
; * main_frame:
; * init_device
; * init_port
; * init_led
; * init_timer
; * init_RF
; * init_uart
; * init_schedule
; * start_myprogram
; * main_schedule
; */
; //ICC-AVR application builder : 2006-9-26 20:14:28
; // Target : M128
; // Crystal: 7.3728Mhz
;
; #include <iom128v.h>
; #include <macros.h>
; #include <stdio.h>
; #include "../api/schedule.h"
; #include "../api/cc1100.h"
; #include "../api/led.h"
; #include "../api/timer.h"
;
;
;
;
;
;
; void port_init(void)
; {
; //cc1100
; /* IN G1 o
; GD0O D1 i
; CSN C2 o
; SCLK G0 o
; OUT C1 i
; */
; //led
; /* led0 C4 o
; led1 C5 o
; led2 C6 o
; */
;
; PORTA = 0x00;
clr R2
out 0x1b,R2
; DDRA = 0x00;
out 0x1a,R2
; PORTB = 0x00;
out 0x18,R2
; DDRB = 0x00;
out 0x17,R2
; PORTC = 0x00; //m103 output only
out 0x15,R2
; DDRC = 0x74;
ldi R24,116
out 0x14,R24
; PORTD = 0x00;
out 0x12,R2
; DDRD = 0x00;
out 0x11,R2
; PORTE = 0x00;
out 0x3,R2
; DDRE = 0x00;
out 0x2,R2
; PORTF = 0x00;
sts 98,R2
; DDRF = 0x00;
sts 97,R2
; PORTG = 0x00;
sts 101,R2
; DDRG = 0x03;
ldi R24,3
sts 100,R24
L1:
.dbline 0 ; func end
ret
.even
_uart0_init::
; }
;
;
;
; //UART0 initialize
; // desired baud rate: 57600
; // actual: baud rate:57600 (0.0%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
; UCSR0B = 0x00; //disable while setting baud rate
clr R2
out 0xa,R2
; UCSR0A = 0x00;
out 0xb,R2
; UCSR0C = 0x06;
ldi R24,6
sts 149,R24
; UBRR0L = 0x07; //set baud rate lo
ldi R24,7
out 0x9,R24
; UBRR0H = 0x00; //set baud rate hi
sts 144,R2
; UCSR0B = 0x18;
ldi R24,24
out 0xa,R24
L2:
.dbline 0 ; func end
ret
.even
_init_devices::
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
;
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
; XDIV = 0x00; //xtal divider
clr R2
out 0x3c,R2
; XMCRA = 0x00; //external memory
sts 109,R2
; port_init(); //端口初始化
xcall _port_init
; led_init(); //所有灯灭
xcall _led_init
; T0_init();
xcall _T0_init
; T2_init();
xcall _T2_init
; T1_init();
xcall _T1_init
; T3_init();
xcall _T3_init
; CC1100_init(); //RF初始化
xcall _CC1100_init
; uart0_init(); //串口初始化
xcall _uart0_init
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
; EICRA = 0x00; //extended ext ints
sts 106,R2
; EICRB = 0x00; //extended ext ints
out 0x3a,R2
; EIMSK = 0x00;
out 0x39,R2
; TIMSK = 0x00; //timer interrupt sources
out 0x37,R2
; ETIMSK = 0x00; //extended timer interrupt sources
sts 125,R2
; SEI(); //re-enable interrupts
sei
L3:
.dbline 0 ; func end
ret
; i -> R20,R21
; xtal -> R22,R23
.even
_delay_1ms::
xcall push_gset2
movw R22,R16
; //all peripherals are now initialized
; }
;
; void delay_1ms(unsigned int xtal)
; {
; unsigned int i;
; for(i=1;i<(unsigned int)(xtal*143-2);i++)
ldi R20,1
ldi R21,0
xjmp L8
L5:
L6:
subi R20,255 ; offset = 1
sbci R21,255
L8:
ldi R16,143
ldi R17,0
movw R18,R22
xcall empy16s
movw R24,R16
sbiw R24,2
cp R20,R24
cpc R21,R25
brlo L5
L4:
xcall pop_gset2
.dbline 0 ; func end
ret
; i -> R20,R21
; n -> R22,R23
.even
_delay_x::
xcall push_gset2
movw R22,R16
; ;
; }
;
; void delay_x(unsigned int n)
; {
; unsigned int i=0;
clr R20
clr R21
; for(i=0;i<n;i++)
xjmp L13
L10:
ldi R16,7
ldi R17,0
xcall _delay_1ms
L11:
subi R20,255 ; offset = 1
sbci R21,255
L13:
cp R20,R22
cpc R21,R23
brlo L10
L9:
xcall pop_gset2
.dbline 0 ; func end
ret
; temp -> <dead>
.even
_main::
; delay_1ms(7);
; }
;
; extern unsigned char T_p_node;
; extern unsigned int T;
; extern unsigned char node_num;
; extern unsigned char LOCAL_GID;
; extern sleep_flag;
; void main()
; {
; int temp;
; T_p_node = (T/node_num*2);
lds R18,_node_num
clr R19
lds R16,_T
lds R17,_T+1
xcall div16u
movw R18,R16
ldi R16,2
ldi R17,0
xcall empy16s
sts _T_p_node,R16
; init_devices();
xcall _init_devices
; CC1100_change_channr(LOCAL_GID*2-1+0xa);
lds R2,_LOCAL_GID
ldi R24,2
mul R24,R2
mov R16,R0
subi R16,1
subi R16,246 ; addi 10
xcall _CC1100_change_channr
; sleep_flag =0;
clr R2
clr R3
sts _sleep_flag+1,R3
sts _sleep_flag,R2
;
; sched_init();
xcall _sched_init
;
; CC1100_setInterrupt(0x01); //RF接收状态
ldi R16,1
xcall _CC1100_setInterrupt
; //CC1100_sleep();
; /*my program*/
; PowerEnable();
xcall _PowerEnable
xjmp L16
L15:
xcall _run_task
L16:
; //start_T1(0,2000);
;
; /*while(1)
; {
; MCUCR = 0x30;
; //asm("sleep");
; //MCUCR =0x0;
; led1Toggle();
; }
; while(1) ;
; */
; //while(1);
; //start_T3(1,24000);
; //start_T0(1,1000);
; //start_T2(1,5000);
; //printf("begin\n");
; /*
; while(1){
; temp = get_tmp();
; printf("tmp is %d",temp);
; delay_x(1000);
; }
; */
;
; /*my program end*/
;
; /*schedule*/
; while(1)
xjmp L15
X0:
L14:
.dbline 0 ; func end
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -