|
|
View previous topic :: View next topic |
Author |
Message |
leevise
Joined: 05 Aug 2010 Posts: 89
|
PIC18f452 MCU control TC35I GSM module---Solved!! |
Posted: Fri Oct 07, 2011 8:09 pm |
|
|
Hi guys ,
I designed a project that used the PIC18F452 control TC35I module.
The detail info. as follow:
Use the KEY control TC35I module "make a telephone, hang up phone, send the text sms, send the PDU sms".
When I compile it, it is OK, but I when download to target board, display error
ICD ERROR
Could not read target ROM: the returned address was not the onerequested
How I modify this code for successful ???
Appreciate !!!
The code as follow:
Code: |
#include <18f452.h>
#include <string.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
#define PORTA 0xF80
#define PORTB 0xF81
#define PORTC 0xF82
#define PORTD 0XF83
#bit KEY1=PORTB.0 //ring up
#bit KEY2=PORTB.2 //hang up phone
#bit KEY4=PORTB.4 //send a text sms
#bit KEY5=PORTB.5 //send a PDU sms
char num[]="13820835529F"; //define the phone number
char sms[]="6E295EA6FF1A003300350043"; //"温度:35C"的Unicode
//PDU message
char str1[]="AT\n"; //TC35I command 1
char str2[]="AT+CMGF=0\n"; //TC35I command 2
char str3[]="AT+CSCS=GSM\n"; //TC35I command 3
char str4[]="AT+CSMP=17,167,0,8\n"; //TC35I command 4
char str5[]="AT+CMGS="; //TC35I command 5
char str6[]="0891683108200205F011000D9168"; //SMSC
char str7[]="000800"; //TC35I command
// TEXT message
char str8[]="AT\n"; //TC35I command
char str9[]="AT+CMGF=1\n"; //TC35I command
char str10[]="AT+CSCS=GSM\n"; //TC35I command
char str11[]="AT+CSMP=17,167,0,0\n"; //TC35I command
char str12[]="AT+CMGS=13820835529\n"; //TC35I command
char str13[]="Hello world!!"; //ms content
char str14[]="\x1a"; //TC35I command
void GSM_Call(unsigned char *num); //
void GSM_Hang(void); //
void GSM_Answer(void); //
void GSM_Sent_Text_Message(void); //
void GSM_Sent_PDU_Message(char num[],char sms[]);
void main(void)
{
while(TRUE)
{
if(KEY1==0)
{
delay_ms(20);
while(KEY1==0);
{
delay_ms(20);
GSM_Call(num);
}
}
if(KEY2==0)
{
Delay_ms(20);
while(KEY2==0);
{
delay_ms(20);
GSM_Hang();
}
}
if(KEY3==0)
{
delay_ms(20);
while(KEY4==0);
{
delay_ms(20);
GSM_Sent_Text_Message();
}
}
if(KEY4==0)
{
delay_ms(20);
while(KEY5==0);
{
delay_ms(20);
GSM_Sent_PDU_Message(num,sms);
}
}
}
}
/****************************ring the phone**************************/
/*function: GSM_Call(unsigned char *num)
void GSM_Call(unsigned char *num)
{
printf("ATD");
printf("%s;\n",num);
delay_ms(100);
}
/*********************************hang up phone *****************************/
/*function: void GSM_Hang(void)
void GSM_Hang(void)
{
printf("ATH\n");
delay_ms(100);
}
/***************************hang on phone***********************/
/*function type: void GSM_Answer(void)
void GSM_Answer(void)
{
printf("ATA\n");
delay_ms(100);
}
/***********************send TEXT sms*********************/
/*functiontype :GSM_Sent_Text_Message(void)
void GSM_Sent_Text_Message(void)
{
printf("%s",str8);
delay_ms(200);
printf("%s",str9);
delay_ms(200);
printf("%s",str10);
delay_ms(200);
printf("%s",str11);
delay_ms(200);
printf("%s",str12);
delay_ms(200);
printf("%s",str13);
printf("%s",str14);
delay_ms(200);
}
/***********************send PDU sms*********************/
void GSM_Sent_PDU_Message(char num[],char sms[])
{
unsigned char i;
printf("%s",str1);
delay_ms(200);
printf("%s",str2); //set PDU mode,send a Chinese sms
delay_ms(200);
printf("%s",str3); //use GSMCharacter
delay_ms(200);
printf("%s",str4); //set PDU parameter,8 is Unicode
delay_ms(200);
printf("%s",str5);
printf("%d\n",strlen(sms)/2+15); //byte long
delay_ms(200);
printf("%s",str6); //
//strcat(num,"F");
for(i=0;i<6;i++)
{
printf("%c%c",num[2*i+1],num[2*i]);
}
printf("%s",str7); //
printf("%02x",strlen(sms)/2); //
printf("%s\x1a",sms); //
delay_ms(200);
}
|
Last edited by leevise on Wed Oct 26, 2011 6:26 am; edited 2 times in total |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Fri Oct 07, 2011 8:49 pm |
|
|
When I use the 51 series chip, it is work OK !
These 2 code has only difference that the "char " string part.
The 51 code is
Code: |
char code num[]="13820835529F";
char code sms[]="6E295EA6FF1A003300350043";
.........
|
The pic code is
Code: |
char num[]="13820835529F";
char sms[]="6E295EA6FF1A003300350043";
..........
|
Who can tell me how to modify the pic code? Put the string into ROM. |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Fri Oct 07, 2011 11:52 pm |
|
|
what i do that put string into pic ROM ?
some string need put into ROM for visit |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Sat Oct 08, 2011 2:50 am |
|
|
leevise wrote: | what i do that put string into pic ROM ?
some string need put into ROM for visit |
i add the "const " defined the char string :
Code: | const char str1[4]={"AT\n"} |
but the error still come out |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Sat Oct 08, 2011 3:13 am |
|
|
leevise wrote: | leevise wrote: | what i do that put string into pic ROM ?
some string need put into ROM for visit |
i add the "const " defined the char string :
Code: | const char str1[4]={"AT\n"} |
but the error still come out |
Who can tell me the error's reason,and how to modify this code !!
Very Appreciated !!!!! |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Mon Oct 10, 2011 5:50 am |
|
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Oct 10, 2011 8:19 am |
|
|
To put string data into ROM, you use the const construct. _But_, to then use a pointer to this, you need to have the command line up with the fuses, saying #PASS_STRINGS=IN_RAM
The key is to understand that the PIC, uses a Harvard memory architecture, meaning that it has multiple address spaces, one for ROM, and another for RAM, addressed at the same time (different from the PC, or most other micro controllers). Problem this brings, is that there are two address 0's. two address 1's etc.. One in each memory space. So if you put data into ROM, and then want to address it the code needs to 'know' that it must talk to the second memory space. There are two ways to do this:
1) Use the ROM construct rather than const. This adds extra code to extract data from ROM, and an extra bit to say which memory space the data is in.
2) Use '#PASS_STRINGS=IN_RAM'. This adds code so that string data stored in the ROM, is automatically copied into RAM as needed, and pointers can then be used to this.
Best Wishes |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Thu Oct 20, 2011 7:04 am |
|
|
Ttelmah wrote: | To put string data into ROM, you use the const construct. _But_, to then use a pointer to this, you need to have the command line up with the fuses, saying #PASS_STRINGS=IN_RAM
The key is to understand that the PIC, uses a Harvard memory architecture, meaning that it has multiple address spaces, one for ROM, and another for RAM, addressed at the same time (different from the PC, or most other micro controllers). Problem this brings, is that there are two address 0's. two address 1's etc.. One in each memory space. So if you put data into ROM, and then want to address it the code needs to 'know' that it must talk to the second memory space. There are two ways to do this:
1) Use the ROM construct rather than const. This adds extra code to extract data from ROM, and an extra bit to say which memory space the data is in.
2) Use '#PASS_STRINGS=IN_RAM'. This adds code so that string data stored in the ROM, is automatically copied into RAM as needed, and pointers can then be used to this.
Best Wishes |
First, thank you very much!
I use the 2) way to set the ROM, but when I download the code to target board, the ICD always display "Could not read target ROM: the returned address was not the one requested".
Why ? What means about this error ? |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
solved |
Posted: Tue Oct 25, 2011 9:23 pm |
|
|
I post my code, it is successful!
I wish it can help you.
Code: |
#include <18f452.h>
#Device PASS_STRINGS=IN_RAM
#include <string.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
#zero_ram
#define PORTA 0xF80
#define PORTB 0xF81
#define PORTC 0xF82
#define PORTD 0XF83
#bit A1=PORTA.1 //Matrix Keyboard common
#bit col8=PORTC.0 //Matrix LED common
//*****************************************************//
#byte RD=PORTD //
#bit KEY1=PORTB.0 //define sw0 for RB0 ,dial phone
#bit KEY2=PORTB.2 //define sw1 for RB2 ,hang down phone
#bit KEY4=PORTB.4 //define sw2 for RB4 ,send a txt message
#bit KEY5=PORTB.5 //define sw3 for RB5 ,send a Chinese message
#bit LED5=PORTD.5 //Test indicator
#bit LED6=PORTD.6 //SWO indicator
#bit LED7=PORTD.7 //SW1 indicator
const char num[]="xxxxxxx"; //defiend your number
const char sms[]="6E295EA6FF1A003300350043"; //"温度:35C"chinese
//PDU mode
const char str1[]={"AT\r\n"}; //
const char str2[]={"AT+CMGF=0\r\n"}; //
const char str3[]={"AT+CSCS=GSM\r\n"}; //
const char str4[]={"AT+CSMP=17,167,0,8\r\n"}; //
const char str5[]={"AT+CMGS="}; //
const char str6[]={"0891683108200205F011000D9168"}; //set SMSC number:xxxxxxxxxx
const char str7[]={"000800"}; //
// TEXT mode
const char str8[]={"AT\r\n"}; //
const char str9[]={"AT+CMGF=1\r\n"}; //
const char str10[]={"AT+CSCS=GSM\r\n"}; //
const char str11[]={"AT+CSMP=17,167,0,0\r\n"}; //
const char str12[]={"AT+CMGS=15122086956\r\n"}; //
const char str13[]={"Hello world!!i love you ,do you love me?"}; //
const char str14[]={"\x1a"}; //
void GSM_Call(unsigned char *call); //define call function
void GSM_Hang(void); //define hang down function
//void GSM_Answer(void); //define Answering the Phone function
void GSM_Sent_Text_Message(void); //definedTEXTmode
void GSM_Sent_PDU_Message(char num[],char sms[]); //define PDUmode
/***********************send PDU message*********************/
/*function type:GSM_Sent_PDU_Message(void)
/**********************************************************************/
void GSM_Sent_PDU_Message(char num[],char sms[])
{
unsigned char i;
printf("%s",str1);
delay_ms(200);
printf("%s",str2); //设置为PDU模式,适合发送短信内容为中文
delay_ms(200);
printf("%s",str3); //使用GSM字符集
delay_ms(200);
printf("%s",str4); //设置PDU模式参数,8为使用Unicode编码
delay_ms(200);
printf("%s",str5);
printf("%d\r\n",strlen(sms)/2+15); //字节长度,与实际短信内容长度有关
delay_ms(200);
printf("%s",str6); //一开始发送的字符,包括短信中心号码等,这部分一般都是固定不变的,可以不用管它
//strcat(num,"F"); //在接收端号码后面补F,使之成为12位字符
for(i=0;i<6;i++) //然后再两位两位分别调换位置
{
printf("%c%c",num[2*i+1],num[2*i]);
}
printf("%s",str7); //固定字符
printf("%02x",strlen(sms)/2); //中文短信内容字数
printf("%s\x1a",sms); //发送内容的Unicode编码字符串+(CTRL+Z)
delay_ms(200);
}
/********************************主函数********************************/
/*函数原型:void main(void)
/*函数功能:主函数
/*输入参数:无
/*输出参数:无
/**********************************************************************/
void main(void)
{
set_tris_d(0x00);
set_tris_c(0x00);
set_tris_a(0x11);
set_tris_b(0xff);
output_d(0x00);
port_b_pullups(TRUE);
A1=1;
col8=1;
enable_interrupts(INT_TBE);
enable_interrupts(global);
//LED7=0;
while(TRUE)
{
LED5=1;
if(KEY1==0) //如果是按键1按下,则给xxxxxxxxxx 这个号码打电话
{
delay_ms(20);
LED6=1;
while(KEY1==0);
{
delay_ms(20);
GSM_Call(num);
}
}
if(KEY2==0) //如果是按键2按下,则挂断电话
{
Delay_ms(20);
LED6=0;
while(KEY2==0);
{
delay_ms(20);
GSM_Hang();
}
}
/* if(KEY3==0) //如果是按键3按下,则接听电话
{
delay_ms(20);
while(KEY3==0);
{
delay_ms(20);
GSM_Answer();
}
}
*/
if(KEY4==0) //如果是按键4按下,则向xxxxxxxxx 发送一条英文信息
{
delay_ms(20);
while(KEY4==0);
{
delay_ms(20);
GSM_Sent_Text_Message();
}
}
if(KEY5==0) //如果是按键5按下,则向xxxxxxx 发送一条中文信息
{
delay_ms(20);
while(KEY5==0);
{
delay_ms(20);
GSM_Sent_PDU_Message(num,sms);
}
}
}
}
/****************************拨打指定电话函数**************************/
/*函数原型: GSM_Call(unsigned char *num)
/*函数功能:拨打指定电话
/*输入参数:num
/*输出参数:无
/**********************************************************************/
void GSM_Call(unsigned char *call)
{
printf("ATD");
// printf("ATD13820835529;\r\n");
printf("%s;\r\n",num);
delay_ms(100);
}
/*********************************挂机函数*****************************/
/*函数原型: void GSM_Hang(void)
/*函数功能:挂断电话
/*输入参数:无
/*输出参数:无
/**********************************************************************/
void GSM_Hang(void)
{
printf("ATH\r\n");
delay_ms(100);
}
/********************************接电话函数****************************/
/*函数原型: void GSM_Answer(void)
/*函数功能:接听电话
/*输入参数:无
/*输出参数:无
/**********************************************************************/
/*void GSM_Answer(void)
{
printf("ATA\r\n");
delay_ms(100);
}
*/
/***********************给指定号码发送TEXT模式短信*********************/
/*函数原型:GSM_Sent_Text_Message(void)
/*函数功能:给指定号码发送英文短信息。num[]=接收端号码
/*输入参数:无
/*输出参数:无
/**********************************************************************/
void GSM_Sent_Text_Message(void)
{
printf("%s",str8); //以下几个为GSM的AT串口指令,设置短信发送类型
delay_ms(200);
printf("%s",str9); //设置为TEXT模式,适合发送短信内容为英文
delay_ms(200);
printf("%s",str10); //使用GSM字符集
delay_ms(200);
printf("%s",str11); //设置TEXT模式参数
delay_ms(200);
printf("%s",str12); //设置接收端电话号码
delay_ms(200);
printf("%s",str13); //具体发送的内容在此修改
printf("%s",str14); //结束符,相当于键盘的CTRL+Z
delay_ms(200);
}
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|