Sara89
Banned
- Joined
- Dec 22, 2013
- Messages
- 18
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 0
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 void USART_init(void); void USART_trans_char(unsigned char x); void USART_trans_string(char *z, int b); void delay(void); unsigned char myflag=0; char AT[] = {'A','T'}; char CMGF[] = {'C','M','G','F'}; char CMGS[] = {'C','M','G','S'}; char msg[] = {'O','K'}; char phone[] = {'0','7','9','5','9','8','2','7','2','6'}; void main() { USART_init (); delay_ms(00); USART_trans_string(AT, strlen(AT)); delay_ms(500); USART_trans_char (13); USART_trans_char (10); USART_trans_string(AT,strlen(AT)); USART_trans_char (43); //+ USART_trans_string (CMGF, strlen(CMGF)); USART_trans_char (61); //= USART_trans_char (49); //1 USART_trans_char (13); USART_trans_char (10); delay_ms(2500); USART_trans_string(AT,strlen(AT)); USART_trans_char (43); //+ USART_trans_string (CMGS, strlen(CMGS)); USART_trans_char (61); //= USART_trans_char (34); USART_trans_string (phone, strlen (phone)); USART_trans_char (34); USART_trans_char (13); USART_trans_char (10); delay_ms(2500); USART_trans_string (msg, strlen(msg)); USART_trans_char (13); USART_trans_char (10); delay_ms(2500); } void USART_init(void){ TXSTA=0x22; // low speed communication, asynchronous, Tx enable, 8 bit data RCSTA=0x90;// serial port enable, 8 bit data, continuous Rx, no address detection SPBRG=12;//9600 bps TRISC=0x80; //RC7 is Rx while RC6 is Tx INTCON=0xC0; // GIE and PEIE PIE1=PIE1|0x20;// Enable USART Rx interrupt } void USART_trans_char(unsigned char x){ while(!(TXSTA& 0x02)); TXREG=x; } void USART_trans_string(char* z, int b){ int i =0; for (i=0; i<b; i++){ USART_trans_char(z[i]); }}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 void USART_init(void); void USART_trans_char(char x); void USART_trans_string(char *z, char b); void delay(void); unsigned char myflag=0; char AT[] = {'A','T'}; //len=2 but this is not a string !! //better to use: //char AT[] = "AT"; //this is a valid string, strlen(AT) = 2 char CMGF[] = {'C','M','G','F'}; //ditto, len = 4 char CMGS[] = {'C','M','G','S'}; char msg[] = {'O','K'}; char phone[] = {'0','7','9','5','9','8','2','7','2','6'}; void main() { USART_init (); delay_ms(100); USART_trans_string(AT, 2); //in your case a fix number (here:2) must be used delay_ms(500); USART_trans_char (13); USART_trans_char (10); USART_trans_string(AT, 2); USART_trans_char (43); //+ USART_trans_string (CMGF, 4); USART_trans_char (61); //= USART_trans_char (49); //1 USART_trans_char (13); USART_trans_char (10); delay_ms(2500); USART_trans_string(AT, 2); USART_trans_char (43); //+ USART_trans_string (CMGS, 4); USART_trans_char (61); //= USART_trans_char (34); USART_trans_string (phone, 10); //len of phone array; USART_trans_char (34); USART_trans_char (13); USART_trans_char (10); delay_ms(2500); USART_trans_string (msg, 2); USART_trans_char (13); USART_trans_char (10); //delay_ms(2500); } void USART_init(void) { TXSTA=0x22; // low speed communication, asynchronous, Tx enable, 8 bit data RCSTA=0x90;// serial port enable, 8 bit data, continuous Rx, no address detection SPBRG=12;//9600 bps TRISC=0x80; //RC7 is Rx while RC6 is Tx INTCON=0xC0; // GIE and PEIE PIE1=PIE1|0x20;// Enable USART Rx interrupt } void USART_trans_char(char x) { while(!(TXSTA& 0x02)); TXREG=x; } void USART_trans_string(char* z, char b) { for ( ; b ; --b) USART_trans_char(*z++); }
void main() {
USART_init ();
delay_ms(00); [B][COLOR="#FF0000"]<- Problem because zero !![/COLOR][/B]
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 void USART_Init(void); void USART_Write(unsigned char x); void USART_Write_Text(char *z); char AT[] = "AT\r\n"; char CMGF[] = "AT+CMGF=1\r\n"; char CMGS[] = "AT+CMGS=\"0795982726\"\r\n"; //0795982726 char msg[] = "Hi Sara"; void USART_init(void){ TXSTA = 0x22; // low speed communication, asynchronous, Tx enable, 8 bit data RCSTA = 0x90;// serial port enable, 8 bit data, continuous Rx, no address detection SPBRG = 25;//9600 bps TRISC = 0x80; //RC7 is Rx while RC6 is Tx INTCON = 0xC0; // GIE and PEIE } void USART_Write(char x){ while(!TRMT_bit); // wait for previous transmission to finish TXREG = x; } void USART_Write_Text(char *z){ while(*z)USART_Write(*z++); } void Interrupt(){ if(RCIF_bit){ if(OERR_bit){ CREN_bit = 0; //CREN_bit = 1; OERR_bit = 0; } } RCIF_bit = 0; } void main() { TRISA = 0xFF; USART_Init(); Delay_ms(200); CREN_bit = 0; RCIE_bit = 1; while(1){ USART_Write_Text(AT); Delay_ms(1000); USART_Write_Text(CMGF); Delay_ms(1000); USART_Write_Text(CMGS); Delay_ms(2000); USART_Write_Text(msg); USART_Write(0x1A); Delay_ms(5000); } }
void USART_init(void)
{
TXSTA=0; // 0x44 8bits TX enable Async High speed(20Mhz!)
TXSTA.BRGH=1;
TXSTA.TXEN=1;
RCSTA=0x90;// serial port enable, 8 bit data, continuous Rx, no address detection
//SPBRG=130;//9600 bps AT 20Mhz
SPBRG=104;//9600 bps AT 16Mhz with speed error less than -0.8%
TRISC=0x80; //RC7 is Rx while RC6 is Tx
INTCON=0xC0; // GIE and PEIE
PIE1=PIE1|0x20;// Enable USART Rx interrupt
}
Code C - [expand] 1 Delay_ms(0);
Code C - [expand] 1 Delay_ms(1);
Code C - [expand] 1 Delay_ms(1);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 TRISD = 0x20; PORTD = 0x00; while(1){ if(PORTD.F5){ //Is RD5 high? Delay_ms(50); if(PORTD.F5){ //Is RD5 still high? //your code here } } }
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?