#include <pic.h>
#include <htc.h>
__CONFIG(0x3F32);
#define _XTAL_FREQ 20000000
#define BAUD 9600
void pic_init(void);
void uart_init(void);
void uart_transmit(char data);
void uart_string(const char *s);
char gsm[90],rec[]={"+CMTI"};
unsigned int counter,z;
static void interrupt isr(void)
{
if(RCIF==1)
{
counter=0;
gsm[z]=RCREG;
if(z<88) z++;
} //*
if(TMR0IF==1) //Overflow interrupt flag
{
TMR0IF=0;
if(counter<20000) counter++;
if(counter==5000) z=0;
} //*/
}
main()
{
int i;
pic_init(); //initialize PIC
uart_init(); //initialize UART
for(i=0;i<=89;i++) gsm=0x20;
uart_string("AT+CMGS="); //Send message
uart_transmit(0x22); //"
uart_string("+601xxxxxxxx"); //Phone no
uart_transmit(0x22); //"
uart_transmit(0x0D); //Enter
uart_string("Hi, I'm PIC16F877A"); //Text message
uart_transmit(0x0D); //Enter
uart_string("Reply, if you receive this message");
uart_transmit(0x1A); //Ctrl+Z
}
void pic_init(void)
{
TRISA= 0b00000000;
TRISB= 0b00000000;
TRISC= 0b10000000;
OPTION= 0b00000000;
ADCON1= 0b00000110;
INTCON= 0b11100000;
PIE1= 0b00100000; //Enable RX interrupt
PORTA= 0b00000000;
PORTB= 0b00000000;
PORTC= 0b00000000;
}
void uart_init(void)
{
TXSTA=0b10100000;
RCSTA=0b10010000;
SPBRG=(int)(_XTAL_FREQ/(64.0*BAUD)-1);
}
void uart_transmit(char data)
{
while(TXIF==0) continue;
TXREG=data;
}
void uart_string(const char *s)
{
// while(*s)
// uart_transmit(*s++);
//*
while((*s)!='\0')
{
//Wait for TXREG Buffer to become available
while(!TXIF);
//Write data
TXREG=(*s);
//Next goto char
s++;
}
//*/
}
Usart transmit cannot work i don't know why?if(TMR0IF==1) //Overflow interrupt flag
{
TMR0IF=0;
if(counter<20000) counter++;
if(counter==5000) z=0;
}
#include <htc.h>
#include <pic.h>
if(TMR0IF==1) //Overflow interrupt flag
{
TMR0IF=0;
if(counter<20000) counter++;
if(counter==5000) z=0;
}
INTCON= 0b11[COLOR="#FF0000"]0[/COLOR]00000;
INTCON= 0b11[COLOR="#FF0000"]1[/COLOR]00000;
main()
{
int i;
pic_init(); //initialize PIC
uart_init(); //initialize UART
for(i=0;i<=89;i++) gsm=0x20;
uart_string("AT+CMGS="); //Send message
uart_transmit(0x22); //"
uart_string("+601xxxxxxxx"); //Phone no
uart_transmit(0x22); //"
uart_transmit(0x0D); //Enter
uart_string("Hi, I'm PIC16F877A"); //Text message
uart_transmit(0x0D); //Enter
uart_string("Reply, if you receive this message");
uart_transmit(0x1A); //Ctrl+Z
}
Andpic_init(); //initialize PIC
uart_init(); //initialize UART
for(i=0;i<=89;i++) gsm=0x20;
uart_string("AT+CMGS="); //Send message
uart_transmit(0x22); //"
uart_string("+601xxxxxxxx"); //Phone no
uart_transmit(0x22); //"
uart_transmit(0x0D); //Enter
uart_string("Hi, I'm PIC16F877A"); //Text message
uart_transmit(0x0D); //Enter
uart_string("Reply, if you receive this message");
uart_transmit(0x1A); //Ctrl+Z
Andpic_init(); //initialize PIC
uart_init(); //initialize UART
for(i=0;i<=89;i++) gsm=0x20;
uart_string("AT+CMGS="); //Send message
uart_transmit(0x22); //"
uart_string("+601xxxxxxxx"); //Phone no
uart_transmit(0x22); //"
uart_transmit(0x0D); //Enter
uart_string("Hi, I'm PIC16F877A"); //Text message
uart_transmit(0x0D); //Enter
uart_string("Reply, if you receive this message");
uart_transmit(0x1A); //Ctrl+Z
pic_init(); //initialize PIC
uart_init(); //initialize UART
while(1)
{
for(i=0;i<=89;i++) gsm[i]=0x20;
uart_string("AT+CMGS="); //Send message
uart_transmit(0x22); //"
uart_string("+601xxxxxxxx"); //Phone no
uart_transmit(0x22); //"
uart_transmit(0x0D); //Enter
uart_string("Hi, I'm PIC16F877A"); //Text message
uart_transmit(0x0D); //Enter
uart_string("Reply, if you receive this message");
uart_transmit(0x1A); //Ctrl+Z
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?