完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我的任务是在中继上,每当有来自发送者的消息,中继之后,应该有一个确认消息给发送者,中继***作。没有确认消息,我的中继***作,但是每当我插入一个函数来发送一个消息时,我的代码就会出现故障。继电器操作,也没有消息。我不明白为什么会这样。我只是尝试发送MSG,然后它的OK,但在while循环,它没有显示任何结果,在这里接收消息我已经使用中断服务例程。下面我附上代码请通过它,告诉我哪里错了You酸奶
以上来自于百度翻译 以下为原文 hi , my task is to On the relay whenever there is message from sender , after relay on there should be acknowledge message to sender that relay is operated.without acknowledge message my relay is operated , but whenever i inserted a function for sending a message my code get malfunctioning ,neither relay operated nor message . i could not understand why this happening. i simply tried for sending msg then its ok but in while loop it is not showing any result, here to receive message i have used interrupt service routine.below i have attached code please go through it , and tell me where i am wrong thanking you yogesh /////////////////////////////////////////// //LCD decleration// #define TRUE 1 #define bool_val_1 flags. f0 #define LCD_DIR TRISD #define CTRL_DIR TRISB #define LCD PORTD #define RS PORTB.F0 #define E PORTB.F1 #include"lcd.h" ////////////////////////////////////////////////////// #define STRLEN 55 #define index 2 unsigned char flag=0; unsigned char flag1=0; volatile int flag2=0; unsigned char t,send; volatile unsigned char rcindex; volatile unsigned char rcbuf[STRLEN]; unsigned char num[]="918208996450"; unsigned char i,j; unsigned char rcvd[13]; unsigned char Msg[]="Relay On"; unsigned char num1[12]; unsigned char count; void UART_Init(void) { TXSTA.TXEN=1; // enable transmitter TXSTA.BRGH=1; // enable high baud rate RCSTA.CREN=1; // continuous data receiption //configure input output TRISC.TRISC6=1; // rRX pin as a input TRISC.TRISC7=1; // TX pin as a input TRISC.TRISC0=1; SPBRG=103; // set buad rate 9600 PIE1.RCIE=1; //enable USART receive interrupt RCSTA.SPEN=1; //enable USART } ///////////Initialise Message/////////////// void Init_Msg() { UART1_Write_Text("AT+CMGS="+918446323311"r"); delay_ms(500); UART1_Write_text("Relay Opearted r"); UART1_Write(26); UART1_Write(0x1A); } void main() { INTCON.PEIE=1; //enable interrupt INTCON.GIE=1; // enable globle interrupt CTRL_DIR=0X00; LCD_DIR=0X00; init_lcd(); delay_ms(500); //Init_gsm(); UART_Init(); delay_ms(500); UART1_Write_Text("ATE0rn"); delay_ms(500); //USART_puts("intialisation in complete!n"); // UART1_Write_Text("AT+CPBR=3rn"); delay_ms(500); UART1_Write_Text("AT+CMGF = 1r"); Delay_ms(1000); UART1_Write_Text("AT+CNMI=2,2,0,0,0r"); Delay_ms(1000); cmd_lcd(0x80); string_lcd("Init Complete"); while(1) { if(flag) { // check(); //cmd_lcd(0x80); //string_lcd(rcbuf); for(i=8;i<20;i++) {rcvd[i-8]=rcbuf;} if(rcvd[0]=='9') { if(rcvd[1]=='1') { if(rcvd[2]=='8') { if(rcvd[3]=='2') { if(rcvd[4]=='0') { if(rcvd[5]=='8') { if(rcvd[6]=='9') { if(rcvd[7]=='9') { if(rcvd[8]=='6') { if(rcvd[9]=='4') { PORTB.F6=1; delay_ms(500); PORTB.F6=0; delay_ms(1000); UART1_Write_Text("AT+CMGS="+918446323311"r"); delay_ms(500); cmd_lcd(0x80); string_lcd(rcbuf); delay_ms(1000); UART1_Write_text("Relay Opearted "); UART1_Write(26); UART1_Write(0x1A); }}}}}}}}}} flag=0; } } } void interrupt(void) { if(PIR1.RCIF) //check the receive interrupt flag has fired { t=RCREG; if((t!='n')&&(rcindex rcbuf[rcindex]=t; if(rcbuf[0]=='+') { rcindex++; } else { rcindex=0; //reset string index flag=0; } } else { flag=1; rcindex=0;} } PIR1.RCIF=0; } |
|
相关推荐
3个回答
|
|
可能的是,这些结构构件
以上来自于百度翻译 以下为原文 Possibly, these structure members PIR1.RCIF and more, should bePIR1bits.RCIF |
|
|
|
这不是一个完整的程序。配置设置在哪里,包括哪些?在所有其他初始化完成后,不要设置中断使能位。您有一个Voice变量“FLAG2”,这是您永远不会使用的。您使用的是另一个称为“标志”的标志,它应该是易失性的,但不是(任何在中断服务中写入的,并且在服务之外读取的,必须是易失性的)。只要调用一个函数“中断”就不会使它成为中断服务。您必须使用“中断”作为具有不同名称的函数的限定符,例如,这是毫无意义的。这是只读标志。唯一的方法是通过阅读RCREG,你已经完成了。
以上来自于百度翻译 以下为原文 That is not a complete program. Where are the config settings and includes? void main() { INTCON.PEIE=1; //enable interrupt INTCON.GIE=1; // enable globle interrupt Do not set the interrupt enable bits until AFTER all the other initialisation is complete. You have a voatile variable "flag2" which you never use. You do use another called "flag", which should be volatile, but is not. (Anything written inside an interrupt service, and read outside the service, must be volatile.) void interrupt(void) Just calling a function "interrupt" does not make it an interrupt service. You must use "interrupt" as a qualifier for a function with a different name, e.g. void interrupt my_isr(void) PIR1.RCIF=0; This is pointless. That is a read-only flag. The ONLY way to clear it is by reading RCREG, which you have already done. |
|
|
|
对不起,先生,我提到我正在使用Mikro C Pro为PIC。I Mikro C Pro用于设置RCIF标志ISPIR1.RCIF=1的结构;
以上来自于百度翻译 以下为原文 sorry sir i dint mention that i am using Mikroc Pro for PIC. i mikro c pro the structure for setting RCIF flag is PIR1.RCIF=1; |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
738浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 07:55 , Processed in 1.432697 second(s), Total 85, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号