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

📄 gsb.s

📁 单片机控制GSM22来工作
💻 S
📖 第 1 页 / 共 3 页
字号:
	.module gsb.c
	.area text(rom, con, rel)
	.dbfile E:\单片机\AVR程序\GSM_M22/12864.h
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 30
; //包含所需头文件
; #include <ioM16v.h>
; #include <macros.h>
; 
; 
; /*------宏定义------*/
; 
; 
; 
; 
; #include "12864.h"
; #define Rcv_cap 100        //缓冲内容不能超过200个,搜索时不会先前搜
; 
; const uchar L[4] = {0x80,0x90,0x88,0x98};
; uchar Rcv[Rcv_cap+1] = "ab";      //若缓冲足够变大,要改动程序
; //const uchar AT[] = "AT\r";
; //const uchar Settxt[] = "AT+CMGF=1\r";
; uchar Sendtxt[] = "AT+CMGS=\"15986929180\"\r";
; uchar Content[] = "How are you?\x1a";
; uchar Phone[20] = "";         //11+4+4+1
; uchar CPBW[35] = "AT+CPBW=1,\"";
; uchar i_Rcv = 0;
; uchar flagend = 0;
; /*uchar key;
; uchar pbefore = 0;
; uchar pnext;*/
;  uchar Stc1[] = "GSM 发信息中....";
;  /*uchar Stc2[] = "电话簿:";
;  uchar Stc3[] = "1.发送短信";
;  uchar Stc4[] = "2.打电话";*/
	.dbline 31
; 
	nop
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_nus _delay_nus fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nus::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 34
;  
;  
; //端口初始化
	.dbline 35
; void port_init(void)
	clr R20
	clr R21
	.dbline 36
; {
	xjmp L6
L3:
	.dbline 37
	xcall _delay_1us
L4:
	.dbline 36
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 36
	cp R20,R22
	cpc R21,R23
	brlo L3
	.dbline -2
L2:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 40
;  PORTA = 0x0f;
;  DDRA  = 0x0f;
;  PORTB = 0x00;
;  DDRB  = 0x00;
	.dbline 42
	clr R16
	clr R17
	xjmp L11
L8:
	.dbline 42
L9:
	.dbline 42
	subi R16,255  ; offset = 1
	sbci R17,255
L11:
	.dbline 42
;  PORTC = 0x00;
;  DDRC  = 0x00;
	cpi R16,116
	ldi R30,4
	cpc R17,R30
	brlo L8
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 45
;  PORTD = 0x00;
;  DDRD  = 0x00;
; }
	.dbline 46
; /* 
	clr R20
	clr R21
	.dbline 47
; //串口通信初始化
	xjmp L16
L13:
	.dbline 48
	xcall _delay_1ms
L14:
	.dbline 47
	subi R20,255  ; offset = 1
	sbci R21,255
L16:
	.dbline 47
	cp R20,R22
	cpc R21,R23
	brlo L13
	.dbline -2
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e send_8bit _send_8bit fV
;              i -> R20
;             ch -> R22
	.even
_send_8bit::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 58
; void usart_init(void)//9600
; {
;  UCSRB = 0x00;//禁止中断
;  UCSRA = 0x00;
;  UCSRC = BIT(URSEL) | 0x06;
;  UBRRL = 0x33;
;  UBRRH = 0x00;
;  UCSRB = 0x98;
; }*/
;  
; //串口通信初始化
	.dbline 60
; void usart_init(void)    //115200
; {
	clr R20
	xjmp L21
L18:
	.dbline 61
;  UCSRB = 0x00;//禁止中断
	.dbline 61
	sbi 0x1b,3
	ldi R16,1
	ldi R17,0
	xcall _delay_nus
	.dbline 62
;  UCSRA = 0x00;
	mov R16,R22
	mov R17,R20
	xcall lsl8
	mov R24,R16
	andi R24,128
	breq L22
	.dbline 62
	sbi 0x1b,2
	xjmp L23
L22:
	.dbline 63
;  UCSRC = BIT(URSEL) | 0x06;
	cbi 0x1b,2
L23:
	.dbline 64
	cbi 0x1b,3
	ldi R16,1
	ldi R17,0
	xcall _delay_nus
	.dbline 65
L19:
	.dbline 60
	inc R20
L21:
	.dbline 60
	cpi R20,8
	brlo L18
	.dbline -2
L17:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r ch 22 c
	.dbend
	.dbfunc e WriteData _WriteData fV
;           data -> R20
	.even
_WriteData::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 69
;  UBRRL = 0x03;
;  UBRRH = 0x00;
;  UCSRB = 0x98;
; }
; void init_devices(void)
; {
	.dbline 70
;  CLI(); //禁止所有中断
	sbi 0x1b,1
	.dbline 71
;  //cpu_init(); 
	ldi R16,250
	xcall _send_8bit
	.dbline 72
;   //delay_nms(200); 
	mov R16,R20
	andi R16,240
	xcall _send_8bit
	.dbline 73
;  //lcm_init(); 
	mov R16,R20
	andi R16,#0x0F
	swap R16
	xcall _send_8bit
	.dbline 74
;  port_init();
	cbi 0x1b,1
	.dbline -2
L24:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbend
	.dbfunc e WriteCommand _WriteCommand fV
;        command -> R20
	.even
_WriteCommand::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 78
;  lcd12864_init(); 
;  usart_init();
;  SEI();//开全局中断
; }
	.dbline 79
; 
	sbi 0x1b,1
	.dbline 80
; //串行接收结束中断服务程序
	ldi R16,248
	xcall _send_8bit
	.dbline 81
; #pragma interrupt_handler usart_rx_isr:12
	mov R16,R20
	andi R16,240
	xcall _send_8bit
	.dbline 82
; void usart_rx_isr(void)  
	mov R16,R20
	andi R16,#0x0F
	swap R16
	xcall _send_8bit
	.dbline 83
; { 
	cbi 0x1b,1
	.dbline -2
L25:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r command 20 c
	.dbend
	.dbfunc e guangbiao _guangbiao fV
;              x -> R20
	.even
_guangbiao::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 87
; 	uchar temp;
; 	temp = UDR;
;    if(i_Rcv>(Rcv_cap-1))
;    {
	.dbline 88
;     i_Rcv=0;   
	cpi R20,1
	brne L27
	.dbline 88
	ldi R16,15
	xcall _WriteCommand
	xjmp L28
L27:
	.dbline 89
	ldi R16,12
	xcall _WriteCommand
L28:
	.dbline -2
L26:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r x 20 c
	.dbend
	.dbfunc e Set_display_Adress _Set_display_Adress fV
;        address -> R20
;              x -> R22
;              y -> R20
	.even
_Set_display_Adress::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 94
;    }
;    if((temp!=0x0d)&&(temp!=0x0a)) //
;    {
;     flagend = i_Rcv;
; 	Rcv[i_Rcv] = temp;
; 	i_Rcv++;
	.dbline 96
;    }
;    //flagend = i_Rcv;
	clr R21
	cpi R20,0
	cpc R20,R21
	breq L33
X0:
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	breq L34
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	breq L35
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	breq L36
	xjmp L30
X1:
	.dbline 97
; }
L33:
	.dbline 99
; 
; //判断发送是否成功
	mov R20,R22
	subi R20,128    ; addi 128
	.dbline 100
; uchar ISok(uchar *msure)
	xjmp L31
L34:
	.dbline 102
; {
;  
	mov R20,R22
	subi R20,112    ; addi 144
	.dbline 103
;  if((flagend-1)>flagend)
	xjmp L31
L35:
	.dbline 105
;  {
;   if((Rcv[flagend]==msure[1])&&(Rcv[Rcv_cap-1]==msure[0])) //大写
	mov R20,R22
	subi R20,120    ; addi 136
	.dbline 106
;    return 1;
	xjmp L31
L36:
	.dbline 108
;   else
;    return 0;
	mov R20,R22
	subi R20,104    ; addi 152
	.dbline 109
;  }
L30:
L31:
	.dbline 111
;  else if((Rcv[flagend]==msure[1])&&(Rcv[flagend-1]==msure[0]))
;   return 1;
	mov R16,R20
	xcall _WriteCommand
	.dbline -2
L29:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r address 20 c
	.dbsym r x 22 c
	.dbsym r y 20 c
	.dbend
	.dbfunc e display_String _display_String fV
;              i -> R20
;              s -> R22,R23
;              x -> R10
;              y -> R12
	.even
_display_String::
	xcall push_gset5
	mov R10,R18
	mov R12,R16
	ldd R22,y+10
	ldd R23,y+11
	.dbline -1
	.dbline 115
;  else
;   return 0;
; }
; //发送
	.dbline 116
; void USART_Transmit( unsigned char *T)
	clr R20
	.dbline 117
; { 
	movw R30,R22
	ldd R2,z+0
	tst R2
	brne L38
	.dbline 117
	xjmp L37
L38:
	.dbline 118
; 
	clr R20
L40:
	.dbline 119
;   uchar i = 0;
	.dbline 120
;   while(T[i])           //length--,循环length次
	mov R30,R20
	clr R31
	add R30,R22
	adc R31,R23
	ldd R2,z+0
	tst R2
	brne L44
	.dbline 120
	xjmp L42
L44:
	.dbline 121
;   {
	tst R20
	brne L48
	ldi R24,1
	ldi R25,0
	movw R14,R24
	xjmp L49
L48:
	clr R14
	clr R15
L49:
	ldi R18,2
	ldi R19,0
	movw R16,R14
	xcall mod16s
	cpi R16,0
	cpc R16,R17
	breq L46
X2:
	.dbline 122
;    while ( !( UCSRA & (1<<UDRE)) )
	mov R18,R10
	mov R16,R12
	xcall _Set_display_Adress
L46:
	.dbline 123
;    ;
	mov R30,R20
	clr R31
	add R30,R22
	adc R31,R23
	ldd R16,z+0
	xcall _WriteData
	.dbline 124
;    UDR = T[i];
	ldi R17,2
	mov R16,R20
	xcall mod8u
	tst R16
	breq L50
	.dbline 124
	inc R10
L50:
	.dbline 125
;    i++;
	ldi R24,7
	cp R24,R10
	brsh L52
	.dbline 125
	.dbline 125
	inc R12
	clr R10
	.dbline 125
L52:
	.dbline 126
L41:
	.dbline 118
	inc R20
	.dbline 118
	xjmp L40
L42:
	.dbline -2
L37:
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r s 22 pc
	.dbsym r x 10 c
	.dbsym r y 12 c
	.dbend
	.dbfunc e display_Char _display_Char fV
;             ch -> y+4
;              x -> R22
;              y -> R20
	.even
_display_Char::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 130
;   }
;   
; }
; 
; void sendcmd(uchar *command,uchar *msure,uint t)    //可以改进,用do while()
	.dbline 131
; {static i=0;//用于观察发送AT指今的情况
	mov R18,R22
	mov R16,R20
	xcall _Set_display_Adress
	.dbline 132
;  while(!ISok(msure))
	ldd R16,y+4
	xcall _WriteData
	.dbline -2
L54:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l ch 4 c
	.dbsym r x 22 c
	.dbsym r y 20 c
	.dbend
	.dbfunc e display_Num _display_Num fV
;            tmp -> y+0
;              i -> R20
;              N -> R22
;            num -> R10,R11
;              x -> R12
;              y -> R14
	.even
_display_Num::
	xcall push_gset5
	mov R12,R18
	mov R14,R16
	sbiw R28,5
	ldd R10,y+15
	ldd R11,y+16
	ldd R22,y+17
	.dbline -1
	.dbline 137
;  {    
; 	  i++;
; 	  display_Num(1,0,i,3);
;   USART_Transmit(command);
;   delay_nms(t);
	.dbline 140
;  }
;  i=0;
;  //display(1,Rcv,0);
	clr R20
	xjmp L59
L56:
	.dbline 141
	.dbline 142
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall mod16u
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 143
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall div16u
	movw R10,R16
	.dbline 144
L57:
	.dbline 140
	inc R20
L59:
	.dbline 140
	cp R20,R22
	brlo L56
	.dbline 144
; }
; 
; 
; void clearf(void)         //为下一次写指令做准备
	.dbline 145
; {
	dec R20
	xjmp L61
L60:
	.dbline 147
;  uchar i;
;  i = flagend - 1;
	.dbline 148
;  if(i<flagend)
	mov R18,R12
	mov R16,R14
	xcall _Set_display_Adress
	.dbline 149
;  {
	mov R2,R20
	clr R3
	subi R20,1
	movw R24,R28
	mov R30,R2
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	subi R16,208    ; addi 48
	xcall _WriteData
	.dbline 150
;   flagend = i;
	tst R20
	brne L63
	.dbline 151
;  }
	.dbline 151
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	subi R16,208    ; addi 48
	xcall _WriteData

⌨️ 快捷键说明

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