打印

通过Psoc和Mc55实现拨通电话的C程序

[复制链接]
527|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zwll|  楼主 | 2017-4-23 21:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
通过Psoc和Mc55实现拨通电话的C程序
沙发
kangzj| | 2017-4-23 21:38 | 只看该作者
#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

void main()
{
int timerTicks;
long int i,j;
char * strPtr; // Parameter pointer
unsigned char Command_AT[] ={0x41,0x54,0x0D};
unsigned char Command_CALL[16] ={0x41,0x54,0x44,0x31,0x35,0x31,0x32,0x30,0x30,0x37,0x37,0x32,0x37,0x36,0x3B,0x0D};
UART_1_CmdReset(); // Initialize receiver/cmd
// buffer
UART_1_EnableInt(); // Enable RX interrupts
Counter8_1_WritePeriod(155); // Set up baud rate generator
Counter8_1_WriteCompareValue(77);
Counter8_1_Start(); // Turn on baud rate generator
UART_1_Start(UART_1_PARITY_NONE); // Enable UART
M8C_EnableGInt ; // Turn on interrupts
//UART_1_CPutString("\r\nWelcome to PSoC UART test program. V1.1 \r\n");

timerTicks = 0;
while(1) {
UART_1_PutString(Command_AT);
//UART_1_PutCRLF();
for(i=3000;i>=0;i--)
{for(j=100;j>=0;j--)
{timerTicks++;
if (timerTicks > 254)
     timerTicks = 0;
}
}
strPtr = UART_1_szGetParam();
//UART_1_PutString(strPtr);
//UART_1_PutCRLF();
//while( 1 )
//{
UART_1_PutString(Command_CALL);
//UART_1_PutCRLF();
for(i=3000;i>=0;i--)
{for(j=1000;j>=0;j--)
{timerTicks++;
if (timerTicks > 254)
     timerTicks = 0;
}
}
}
}
以上是我自己写的程序。

使用特权

评论回复
板凳
zwll|  楼主 | 2017-4-23 21:40 | 只看该作者
多谢楼上,能讲讲吗?

使用特权

评论回复
地板
juventus9554| | 2017-4-23 21:41 | 只看该作者
我单独让psoc跟串口专家连接时,串口专家能够显示来自psoc的AT以及ATD……等,让mc55单独跟串口专家连接时,串口专家能够发送AT指令并且成功通信。

使用特权

评论回复
5
zwll|  楼主 | 2017-4-23 21:42 | 只看该作者
但是让两者连接的时候单片机就不能给mc55发指令了

使用特权

评论回复
6
zwll|  楼主 | 2017-4-23 21:44 | 只看该作者
两者是通过RXD跟TXD交叉连接的。

使用特权

评论回复
7
pengf| | 2017-4-23 21:45 | 只看该作者
;--------******〈〉〈〉〈〉数据发送模块〈〉〈〉〈〉******-----
DATA_SEND:
MOV R1,#00H
setb 07h
clr 09h
mov r1,#0h
DIAL: ;接通线路
mov r2,#0h
dial0:
INC R1
n1: mov a,p3
jnb acc.5,n1
setb p1.4
ACALL SENDN_PERPAL ;置8880发送状态
mov r5,#0h
de_1: cjne r5,#2h,de_1
DIAL1: MOV R0,#10H ;拨电话
DI11: MOV A,@R0
cjne a,#41h,di_1
mov a,#0ah
di_1:
CJNE A,#42H,DIAL2 ;“A”为电话结束字
SJMP DIAL3 ;
DIAL2: ACALL SEND
INC R0
; mov r5,#0h
;dpa: cjne r5,#1h,dpa
SJMP DI11
;---------------------- ;接收应答的两“#”号
DIAL3: setb p1.4
ACALL RECV_PERPAL ;置8880接收状态
MOV R6,#0h ;超时控制字2
DIAL4: ACALL RECV ;接收一
次 JB
08H,DIAL5 ;收到则转处理程序DIAL5
JB 08H,DIAL5
;----------
mov a,#09h
mov sbuf,a
dial_d0:
jnb ti,dial_d0
clr ti
;-----------
CJNE R6,#10,DIAL4 ;2#AT 2S ;两秒内收不到且未超时9
秒则重拨
inc r2
;befoen errer control send some Message
;to tell that : It is me!
ACALL SENDN_PERPAL ;置8880发送状态
mov a,#05h
acall send
acall send
acall send
;----------
mov a,#10h
mov sbuf,a
dial_d1:
jnb ti,dial_d1
clr ti
;-----------
clr p1.4
mov r5,#0h
de_9: ;----------
mov a,#11h
mov sbuf,a
dial_d2:
jnb ti,dial_d2
clr ti
;-----------
cjne r5,#8h,de_9
cjne r1,#20h,dial0
CLR P1.4 ;仍未拨通则暂停 挂机
;because it is no a special line to call phone
; dont't take this line too much time
;
; mov r5,#0h
;de_0: cjne r5,#10h,de_0
; inc r1
; cjne r1,#2h,dial
MOV SBUF,#01H
ER_1: JNB TI,ER_1
CLR TI
ret
;--------------------
DIAL5: CLR 08H
anl a,#0fh
CJNE A,#08H,DIAL4 ;
JB 09H,dial7 ;收到两个“#”号才转入发

SETB 09H
SJMP DIAL4 ;仅收到一个则继续收
;----------------- ;开始发送数据
dial7: ;mov sbuf,#00h
acall sendn_perpal
mov a,#0ch
acall send
;debug========
mov r5,#0h
del_9: cjne r5,#2h,del_9
MOV R2,#0H
mov r3,#0h
TEL_S: ;;debug=======
; acall sendn_perpal
mov b,#0fh
mov a,#01h
acall send
xrl a,b
mov b,a
mov a,#08h ;Zhan Name
acall send
xrl a,b
mov b,a
mov dptr,#0e040h
movx a,@dptr
mov r0,a
swap a
anl a,#0fh
acall send
xrl a,b
mov b,a
movx a,@dptr
anl a,#0fh
acall send
xrl a,b
mov b,a
inc dptr
cjne r0,#01h,normal
sjmp da_end
normal: dec r0
go_send:movx a,@dptr
anl a,#0fh
acall send
xrl a,b
mov b,a
inc dptr
djnz r0,go_send
da_end: mov a,#0ah
acall send
xrl a,b
mov b,a
mov a,#0ah
acall send
xrl a,b
mov b,a
acall send
TEL_CHECK:
acall recv_perpal
; setb p1.4
MOV R6,#0H ;超时判断字
TEL_C1: ACALL RECV
JB 08H,TEL_C2 ;接收到信号转入处理
MOV SBUF,#07H
ER_9: JNB TI,ER_9
CLR TI
T_CE: CJNE R6,#12,TEL_C1 ;十二秒内仍继续检测
inc r3
CJNE R3,#4,TEL_S ;置无返回字错误
;debug===============
clr p1.4
ss: MOV SBUF,#02H
ER_2: JNB TI,ER_2
CLR TI
ljmp data_send
TEL_C3: CJNE A,#05H,T_CE ;传输错则置错误字
;dec r3
acall sendn_perpal
NOP
NOP
;.LJMP TEL_S
LJMP DATA_send
;重传
;---------------- ;返回字处理
TEL_C2:
;----debug----
mov sbuf,a
ddfd: jnb ti,ddfd
clr ti
;aaaf: sjmp aaaf
;----------------
mov r5,#00h
cjne a,#06h,TEL_C3
mov dptr,#0e040h
mov a,#01h
movx @dptr,a
mov dptr,#0f000h
mov b,#0fh
NOP
NOP
MOV R6,#0H
TEL_C20:
ACALL RECV
JB 08H,TEL_C21
CJNE R6,#10H,TEL_C20
acall sendn_perpal
mov a,b
jnz cn_a
movx @dptr,a
mov r0,dpl
cjne r0,#26h,cn_ab
sjmp c_a
cn_a: mov a,#04h
acall send
mov a,#04h
acall send
mov r5,#0h
hom: cjne r5,#02h,hom
mov r0,b
sound: mov a,#04h
acall send
djnz r0,sound
clr p1.4
MOV SBUF,#03H
ER_3: JNB TI,ER_3
CLR TI
ret
cn_ab: mov a,#04h
acall send
sjmp cn_a
TEL_C21:
movx @dptr,a
inc dptr
xrl a,b
mov b,a
mov r6,#00h
ljmp tel_c20
;-------------------------
c_a: acall sendn_perpal
mov a,#05h
acall send
;===debug
; clr p1.4
mov dptr,#0f001h ;上位机中求得的当前时间写入DS1643
movx a,@dptr
swap a
anl a,#0f0h
mov r0,a
inc dptr
movx a,@dptr
anl a,#0fh
add a,r0
mov hour_r,a
inc dptr
movx a,@dptr
swap a
anl a,#0f0h
mov r0,a
inc dptr
movx a,@dptr
anl a,#0fh
add a,r0
mov minute_r,a
acall write_ds1643
mov r1,#30h
gog: inc dptr ;将高字节屏蔽掉,同时写入30H中
movx a,@dptr
swap a
anl a,#0f0h
mov r0,a
inc dptr
movx a,@dptr
anl a,#0fh
add a,r0
mov @r1,a
inc r1
cjne r1,#40h,gog
mov dptr,#0e000h ;将时间表写入E000H--E01FH
mov r0,#30h
goo: mov a,@r0
movx @dptr,a
inc dptr
inc r0
cjne r0,#03eh,goo
acall read_ds1643
mov dptr,#0e011h ;当前时间为起点求采样时间存入
E011?-E02FH
mov r0,3fh
mov a,minute_r
add a,r0
mov b,#5ah
div ab
mov r0,a
mov a,b
da a
movx @dptr,a
mov a,3eh
add a,r0
mov r0,a
mov dptr,#0e010h
mov a,hour_r
add a,r0
mov b,#24h
div ab
mov a,b
da a
movx @dptr,a
mov r1,#0h
mov r2,#0h
mov r3,#0h
mov dptr,#0e011h
fff: cjne r3,#01h,ffy
mov a,#0ffh
inc dptr
movx @dptr,a
inc dptr
inc r1
cjne r1,#0fh,fff
ljmp fft
ffy:
movx a,@dptr
mov r0,3fh
add a,r0
mov b,#5ah
div ab
mov r0,a
mov a,b
da a
inc dptr
inc dptr
movx @dptr,a
dec dpl
dec dpl
dec dpl
movx a,@dptr
add a,r0
mov r0,3eh
add a,r0
mov b,#024h
div ab
inc dptr
inc dptr
mov a,b
da a
mov r4,a
subb a,hour_r
jc tak
cjne r2,#01h,toi
mov r3,#01h
mov a,#0ffh
sjmp tti
tak: mov r2,#1h
sjmp toi
toi: mov a,r4
tti: movx @dptr,a
inc dptr
inc r1
cjne r1,#0fh,fff
fft: clr p1.4
MOV SBUF,#04H
ER_4: JNB TI,ER_4
CLR TI
mov r5,#0h
tim_lay:cjne r5,#40h,tim_lay
ret
; -----*******-----------********---------
; -----*******-----------********---------
int_t0: push acc
push psw

CPL p3.3
djnz 0ah,t0B
mov 0ah,#10
inc r5
inc r6
inc r7
t0b: pop psw
pop acc
mov tl0,#00h
mov th0,#010h
reti
; **********************************
; ----------------------------------------------------
send: push acc
anl a,#1fh
mov p1,#1fh
anl p1,a
setb p1.7
clr p1.7
mov r5,#0
mov p1,#7fh
t60: setb p1.7
mov a,p1
clr p1.7
jb 0e1h,t61
cjne r5,#3,t60
pop acc
sjmp send
t61:
nop
pop acc
ret
; ----------------------------------
recv: mov p1,#7fh ;recieve
setb p1.7 ;p3.2
mov a,p1
clr p1.7
jb 0e2h,t2
clr 08h
ret
t2: mov p1,#3fh
setb p1.7
mov a,p1
clr p1.7
anl a,#0fh
setb 08h
ret
; +++++++++++++++++++++++++++++++++++
sendn_perpal:
mov p1,#51h
setb p1.7
clr p1.7
setb P3.2
ret
; ***********************************
recv_perpal:
mov p1,#01010101b
setb p1.7
clr p1.7
clr P3.2
ret
; -----------------------------------!!!!
;=====INATIAL DS1643======
INATIAL_DS1643:
push ACC
PUSH DPH
PUSH DPL
MOV DPTR, #CONTROL
MOV A, #80H
MOVX @DPTR, A ;WRITE ENABLE
MOV DPTR, #DAY
MOVX A, @DPTR
ANL A, #DAY_F
MOVX @DPTR, A ;FT DIABLE
MOV DPTR, #SECOND
MOVX A, @DPTR
ANL A, #SEC_F
MOVX @DPTR, A ;OSC ENABLE
; MOV DPTR, #HOUR
;mov a,#12h
;MOVX @DPTR, a

;MOV DPTR, #MINUTE
;mov a,#36h
;MOVX @DPTR,a
;MOV DPTR, #SECOND
;mov a,#50h
;MOVX @DPTR,a

MOV DPTR, #CONTROL
MOV A, #00H
MOVX @DPTR, A
POP DPL
POP DPH
POP ACC
RET
;=========================
READ_DS1643:
PUSH ACC
PUSH DPH
PUSH DPL
MOV DPTR, #CONTROL
MOV A, #40H
MOVX @DPTR, A ;READ ENABLE
MOV DPTR, #HOUR
MOVX A, @DPTR
MOV HOUR_R, A
MOV DPTR, #MINUTE
MOVX A, @DPTR
MOV MINUTE_R, A
MOV DPTR, #SECOND
MOVX A, @DPTR
MOV SECOND_R, A
MOV DPTR, #CONTROL
MOV A, #00H
MOVX @DPTR, A ;READ CLOSE
POP DPL
POP DPH
POP ACC
RET
;=========================
WRITE_DS1643:
PUSH ACC
PUSH DPH
PUSH DPL
MOV DPTR, #CONTROL
MOV A, #80H
MOVX @DPTR, A ;WRITE ENABLE
MOV DPTR, #HOUR
MOV A, HOUR_R
ANL A, #HOU_F
MOVX @DPTR, A
MOV DPTR, #MINUTE
MOV A, MINUTE_R
ANL A, #MIN_F
MOVX @DPTR, A
MOV DPTR, #SECOND
MOV A, SECOND_R
ANL A, #SEC_F
MOVX @DPTR, A
MOV DPTR, #CONTROL
MOV A, #00H
MOVX @DPTR, A ;RUN
POP DPL
POP DPH
POP ACC
RET
;********************************************

; mov r0,#30h
; mov dptr,#0f000h
;ttt:
; mov a,@r0
; movx @dptr,a
; inc r0
; inc dptr
; ajmp ttt
;************************************************
TEL_NUM: DB 36h,33h,32h,34h,31h,42h,70H
;************************************************
end

使用特权

评论回复
8
supernan| | 2017-4-23 21:47 | 只看该作者
AT指令吧

使用特权

评论回复
9
zwll|  楼主 | 2017-4-23 21:48 | 只看该作者
哦,那我就知道怎么回事了,多谢大家,结贴了哈

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

885

主题

11314

帖子

5

粉丝