📄 test_7135.s
字号:
.module test_7135.c
.area data(ram, con, rel)
_N::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile test_7135.c
.dbsym e N _N c
_T1OVF_NUM::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile test_7135.c
.dbsym e T1OVF_NUM _T1OVF_NUM i
.area text(rom, con, rel)
.dbfile test_7135.c
.dbfunc e DELAY_1MS _DELAY_1MS fV
; i -> R16,R17
.even
_DELAY_1MS::
.dbline -1
.dbline 47
; //*************************************************
; //测试功能:7135的ad功能。
; //测试方法:注意:采集到的电压单位为mv
; //测试结果:ok
; //时钟频率:外部8m
; //管脚分配:1脚(pb0)接7135的25,4脚(pb3)接7135的22
; //16脚(pd2)接7135的21
; //注意事项:基准电压为:1v.输入电压不大于2v
; //完成时间:2009.03.17
; //**************************************************
;
; //**************************************************
; //头文件
; //**************************************************
; #include <iom16v.h>
; #include <macros.h>
; //**************************************************
;
;
; //*****************************************************
; //全局变量定义
; //*****************************************************
; unsigned char N=0;//用来区别是第一次外部中断还是第二次中断
; unsigned int T1OVF_NUM=0;//用来计定时器T1的溢出次数
; unsigned long int T1_NUM;//T1计的总时钟的个数
; unsigned int VIN;//测到的电压,单位为mv
;
; //*****************************************************
; //函数声明
; //*****************************************************
; void DELAY_1MS(void);
; void DELAY_NMS(unsigned int n);
; void PORT_INIT(void);
; void INT0_INIT(void);
; void T1_INIT(void);
; void T0_125K(void);
; void USART_INIT(void);
; void USART_TX(unsigned char data);
; void DATA_DISPLAY(unsigned int data);
;
; //*****************************************************
; //函数名称:void DELAY_1MS(void)
; //函数功能:延时1ms
; //注意事项:i=143*n-2
; //*****************************************************
; void DELAY_1MS(void)
; {
.dbline 49
; unsigned int i;
; for(i=1142;i>0;i--)
ldi R16,1142
ldi R17,4
xjmp L5
L2:
.dbline 50
L3:
.dbline 49
subi R16,1
sbci R17,0
L5:
.dbline 49
cpi R16,0
cpc R16,R17
brne L2
X0:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e DELAY_NMS _DELAY_NMS fV
; n -> R20,R21
.even
_DELAY_NMS::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 58
; ;
; }
; //*****************************************************
; //函数名称:void DELAY_NMS(void)
; //函数功能:延时Nms
; //注意事项:
; //*****************************************************
; void DELAY_NMS(unsigned int n)
; {
.dbline 59
; for(;n>0;n--)
xjmp L10
L7:
.dbline 60
xcall _DELAY_1MS
L8:
.dbline 59
subi R20,1
sbci R21,0
L10:
.dbline 59
cpi R20,0
cpc R20,R21
brne L7
X1:
.dbline -2
L6:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r n 20 i
.dbend
.dbfunc e PORT_INIT _PORT_INIT fV
.even
_PORT_INIT::
.dbline -1
.dbline 68
; DELAY_1MS();
; }
; //*****************************************************
; //函数名称:void INT0_INIT(void)
; //函数功能:int0初始化,上升沿产生中断,使能中断
; //注意事项:未开总中断
; //*****************************************************
; void PORT_INIT(void)
; {
.dbline 69
; DDRB=0X09;
ldi R24,9
out 0x17,R24
.dbline 70
; PORTB=0X00;
clr R2
out 0x18,R2
.dbline 71
; DDRD=0X00;
out 0x11,R2
.dbline 72
; PORTD=0XFF;
ldi R24,255
out 0x12,R24
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e T0_125K _T0_125K fV
.even
_T0_125K::
.dbline -1
.dbline 81
; }
;
; //**********************************************************
; //函数名称:void T0_250K(void)
; //函数功能:t0工作于CTC模式,产生250k方波
; //注意事项:一分频,pb3(oc0)接7135 clk
; //**********************************************************
; void T0_125K(void)
; {
.dbline 82
; TCCR0=0X00;
clr R2
out 0x33,R2
.dbline 83
; TCNT0=0X00;
out 0x32,R2
.dbline 84
; OCR0=31;
ldi R24,31
out 0x3c,R24
.dbline 85
; TIMSK&=~(1<<OCIE0);
in R24,0x39
andi R24,253
out 0x39,R24
.dbline 86
; TCCR0=0X19;
ldi R24,25
out 0x33,R24
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbend
.dbfunc e INT0_INIT _INT0_INIT fV
.even
_INT0_INIT::
.dbline -1
.dbline 94
; }
; //*****************************************************
; //函数名称:void INT0_INIT(void)
; //函数功能:int0初始化,上升沿产生中断,使能中断
; //注意事项:未开总中断
; //*****************************************************
; void INT0_INIT(void)
; {
.dbline 95
; MCUCR|=((1<<ISC01)|(1<<ISC00));
in R24,0x35
ori R24,3
out 0x35,R24
.dbline 96
; GICR|=(1<<INT0);
in R24,0x3b
ori R24,64
out 0x3b,R24
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 4
jmp _INT0_INTERRUPT
.area text(rom, con, rel)
.dbfile test_7135.c
.dbfunc e INT0_INTERRUPT _INT0_INTERRUPT fV
.even
_INT0_INTERRUPT::
xcall push_lset
xcall push_gset2
.dbline -1
.dbline 105
; }
; //*****************************************************
; //函数名称:void INT0_INTERRUPT(void)
; //函数功能:中断处理,N+1
; //注意事项:
; //*****************************************************
; #pragma interrupt_handler INT0_INTERRUPT:2
; void INT0_INTERRUPT(void)
; {
.dbline 106
; if(!N)
lds R2,_N
tst R2
brne L15
.dbline 107
; {
.dbline 108
; TCCR1B=0X01;//开始内部计数
ldi R24,1
out 0x2e,R24
.dbline 109
; MCUCR=0X02;//设置外部中断0下降沿产生中断
ldi R24,2
out 0x35,R24
.dbline 110
; N++;
mov R24,R2
subi R24,255 ; addi 1
sts _N,R24
.dbline 111
; }
xjmp L16
L15:
.dbline 113
.dbline 114
clr R2
out 0x2e,R2
.dbline 115
cli
.dbline 117
lds R2,_T1OVF_NUM
lds R3,_T1OVF_NUM+1
clr R4
clr R5
sts _T1_NUM+1,R3
sts _T1_NUM,R2
sts _T1_NUM+2+1,R5
sts _T1_NUM+2,R4
.dbline 118
lds R4,_T1_NUM+2
lds R5,_T1_NUM+2+1
lds R2,_T1_NUM
lds R3,_T1_NUM+1
ldi R20,0
ldi R21,0
ldi R22,1
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
movw R2,R16
movw R4,R18
in R6,0x2c
in R7,0x2d
clr R8
clr R9
add R2,R6
adc R3,R7
adc R4,R8
adc R5,R9
sts _T1_NUM+1,R3
sts _T1_NUM,R2
sts _T1_NUM+2+1,R5
sts _T1_NUM+2,R4
.dbline 119
ldi R24,6
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsr32
sts _T1_NUM+1,R17
sts _T1_NUM,R16
sts _T1_NUM+2+1,R19
sts _T1_NUM+2,R18
.dbline 120
ldi R20,17
ldi R21,39
ldi R22,0
ldi R23,0
movw R2,R16
movw R4,R18
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
sts _T1_NUM+1,R3
sts _T1_NUM,R2
sts _T1_NUM+2+1,R5
sts _T1_NUM+2,R4
.dbline 121
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
movw R16,R2
movw R18,R4
xcall div32u
sts _VIN+1,R17
sts _VIN,R16
.dbline 122
xcall _DATA_DISPLAY
.dbline 124
clr R2
clr R3
sts _T1OVF_NUM+1,R3
sts _T1OVF_NUM,R2
.dbline 125
out 0x2d,R3
out 0x2c,R2
.dbline 126
in R24,0x35
ori R24,3
out 0x35,R24
.dbline 127
sts _N,R2
.dbline 128
cbi 0x18,0
.dbline 130
L16:
.dbline -2
L14:
xcall pop_gset2
xcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e T1_INIT _T1_INIT fV
.even
_T1_INIT::
.dbline -1
.dbline 138
; else
; {
; TCCR1B=0X00;//定时器t1停止工作
; CLI();//关中断,进行数据处理
; //数据处理
; T1_NUM=T1OVF_NUM;
; T1_NUM=(T1_NUM*65536+TCNT1);
; T1_NUM/=64;
; T1_NUM-=10001;
; VIN=T1_NUM/10;
; DATA_DISPLAY(VIN);
; //数据处理结束
; T1OVF_NUM=0;
; TCNT1=0X0000;
; MCUCR|=((1<<ISC01)|(1<<ISC00));//设置外部上升沿中断
; N=0;//
; PORTB&=~(1<<0);//上位机发0x01,测量一次,停止ad
; //SEI();先进行1次采样
; }
; }
; //**************************************************
; //函数名称:void T1_INIT(void)
; //函数功能:内部定时
; //注意事项,定时器未工作,定时器工作,需+TCCR1B=0X01;
; //**************************************************
; void T1_INIT(void)
; {
.dbline 139
; TCCR1A=0X00;
clr R2
out 0x2f,R2
.dbline 140
; TCNT1=0X0000;
clr R3
out 0x2d,R3
out 0x2c,R2
.dbline 141
; TIMSK|=(1<<TOIE1);
in R24,0x39
ori R24,4
out 0x39,R24
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 32
jmp _T1_OVF
.area text(rom, con, rel)
.dbfile test_7135.c
.dbfunc e T1_OVF _T1_OVF fV
.even
_T1_OVF::
st -y,R24
st -y,R25
in R24,0x3f
st -y,R24
.dbline -1
.dbline 150
; }
; //**************************************************
; //函数名称:void T1_OVF(void)
; //函数功能:ti溢出处理
; //注意事项:
; //**************************************************
; #pragma interrupt_handler T1_OVF:9
; void T1_OVF(void)
; {
.dbline 151
; T1OVF_NUM++;
lds R24,_T1OVF_NUM
lds R25,_T1OVF_NUM+1
adiw R24,1
sts _T1OVF_NUM+1,R25
sts _T1OVF_NUM,R24
.dbline -2
L18:
ld R24,y+
out 0x3f,R24
ld R25,y+
ld R24,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e USART_INIT _USART_INIT fV
.even
_USART_INIT::
.dbline -1
.dbline 159
; }
; //*****************************************************
; //函数名称:void USART_INIT(void)
; //函数功能:8M,波特率9600
; //注意事项:
; //*****************************************************
; void USART_INIT(void)
; {
.dbline 160
; UBRR=0X33;//fosc=8mhz,波特率9600
ldi R24,51
out 0x9,R24
.dbline 161
; UCSRA=0X20;
ldi R24,32
out 0xb,R24
.dbline 162
; UCSRC=0X86;
ldi R24,134
out 0x20,R24
.dbline 163
; UCSRB=0X98;
ldi R24,152
out 0xa,R24
.dbline -2
L19:
.dbline 0 ; func end
ret
.dbend
.dbfunc e USART_TX _USART_TX fV
; data -> R20
.even
_USART_TX::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 171
; }
; //*****************************************************
; //函数名称:void USART_INIT(void)
; //函数功能:8M,波特率9600
; //注意事项:
; //*****************************************************
; void USART_TX(unsigned char data)
; {
.dbline 172
; UDR=data;
out 0xc,R20
L21:
.dbline 174
L22:
.dbline 173
; while(!(UCSRA&(1<<TXC)))
sbis 0xb,6
rjmp L21
.dbline 175
; ;
; DELAY_NMS(1);
ldi R16,1
ldi R17,0
xcall _DELAY_NMS
.dbline -2
L20:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.area vector(rom, abs)
.org 44
jmp _usart_receive
.area text(rom, con, rel)
.dbfile test_7135.c
.dbfunc e usart_receive _usart_receive fV
; d -> R16
.even
_usart_receive::
st -y,R16
in R16,0x3f
st -y,R16
.dbline -1
.dbline 184
; }
; //*****************************************************
; //函数名称:void USART_INIT(void)
; //函数功能:下位机收到0x01,则进行1次ad转换
; //注意事项:
; //*****************************************************
; #pragma interrupt_handler usart_receive:12
; void usart_receive(void)
; {
.dbline 186
; unsigned char d;
; d=UDR;
in R16,0xc
.dbline 187
; if(d==0x01)
cpi R16,1
brne L25
.dbline 188
; {
.dbline 189
; PORTB|=(1<<0);
sbi 0x18,0
.dbline 190
; SEI();
sei
.dbline 191
; }
xjmp L26
L25:
.dbline 193
.dbline 194
cbi 0x18,0
.dbline 195
cli
.dbline 196
L26:
.dbline -2
L24:
ld R16,y+
out 0x3f,R16
ld R16,y+
.dbline 0 ; func end
reti
.dbsym r d 16 c
.dbend
.dbfunc e DATA_DISPLAY _DATA_DISPLAY fV
; temp -> y+0
; i -> R20
; data -> R20,R21
.even
_DATA_DISPLAY::
xcall push_gset1
movw R20,R16
sbiw R28,4
.dbline -1
.dbline 204
; else
; {
; PORTB&=~(1<<0);
; CLI();
; }
; }
; //*****************************************************
; //函数名称:void USART_INIT(void)
; //函数功能:8M,波特率9600
; //注意事项:
; //*****************************************************
; void DATA_DISPLAY(unsigned int data)
; {
.dbline 206
; unsigned char temp[4],i;
; temp[0]=data/1000;
ldi R18,1000
ldi R19,3
movw R16,R20
xcall div16u
std y+0,R16
.dbline 207
; temp[1]=(data/100)%10;
ldi R18,100
ldi R19,0
movw R16,R20
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
std y+1,R16
.dbline 208
; temp[2]=(data/10)%10;
ldi R18,10
ldi R19,0
movw R16,R20
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
std y+2,R16
.dbline 209
; temp[3]=data%10;
ldi R18,10
ldi R19,0
movw R16,R20
xcall mod16u
std y+3,R16
.dbline 210
; for(i=0;i<4;i++)
clr R20
xjmp L34
L31:
.dbline 211
.dbline 212
movw R24,R28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
xcall _USART_TX
.dbline 213
ldi R16,1
ldi R17,0
xcall _DELAY_NMS
.dbline 214
L32:
.dbline 210
inc R20
L34:
.dbline 210
cpi R20,4
brlo L31
.dbline -2
L27:
adiw R28,4
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym l temp 0 A[4:4]c
.dbsym r i 20 c
.dbsym r data 20 i
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 220
; {
; USART_TX(temp[i]);
; DELAY_NMS(1);
; }
; }
; //**********************************************************
; //主函数
; //**********************************************************
; void main(void)
; {
.dbline 221
; CLI();
cli
.dbline 222
; PORT_INIT();
xcall _PORT_INIT
.dbline 223
; T0_125K();
xcall _T0_125K
.dbline 224
; INT0_INIT();
xcall _INT0_INIT
.dbline 225
; T1_INIT();
xcall _T1_INIT
.dbline 226
; USART_INIT();
xcall _USART_INIT
.dbline 227
; SEI();
sei
L36:
.dbline 230
L37:
.dbline 229
xjmp L36
X2:
.dbline -2
L35:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile test_7135.c
_VIN::
.blkb 2
.dbsym e VIN _VIN i
_T1_NUM::
.blkb 4
.dbsym e T1_NUM _T1_NUM l
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -