TiagoRibeiro
Full Member level 2
- Joined
- Oct 29, 2013
- Messages
- 130
- Helped
- 18
- Reputation
- 36
- Reaction score
- 17
- Trophy points
- 28
- Location
- São Paulo/Brazil
- Activity points
- 765
Worked Jayanth..thank you..
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/*
* File: main.c
* Author: Tiago Ribeiro
*
* Created on 25 de Novembro de 2013, 08:49
*/
#include <p18f26j50.h>
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#include <string.h>
#include <usart.h>
#pragma config XINST = OFF // Extended Instruction Set (Enabled)
#pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit)
#pragma config OSC = HS
#pragma config STVREN = OFF
#pragma config DEBUG = OFF
#pragma config CP0 = OFF
#pragma config IESO = OFF
#define _XTAL_FREQ 12000000
/*
*FOSC= 12MHZ
* Tciclo=4/FOSC = 0,333 us
*/
void inicia(void){
LATCbits.LATC2 = 1;
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
LATCbits.LATC2 = 0;
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
LATCbits.LATC2 = 1;
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
TRISCbits.TRISC6 = 0;//saida = 0
TRISCbits.TRISC7 = 1;//entrada = 1
/***TX Configuration************/
TXSTA1bits.CSRC = 0; //
TXSTA1bits.TX9 = 0; //Selects 8-bit transmission
TXSTA1bits.TXEN = 1; //Transmit is enabled
TXSTA1bits.SYNC = 0; //Asynchronous mode
TXSTA1bits.SENDB = 0; //dont Send Sync Break on next transmission (cleared by hardware upon completion)
TXSTA1bits.BRGH = 1; //High speed
/***RX Configuration************/
RCSTA1bits.SPEN = 1; //Serial port is enabled
RCSTA1bits.RX9 = 0; //Selects 8-bit reception
RCSTA1bits.CREN = 1; //Enables the receiver
RCSTA1bits.ADDEN = 0; //Disables address detection, all bytes are received and ninth bit can be used as parity bit
/***BAUDRATE Configuration************/
BAUDCON1bits.ABDOVF = 0; //No BRG rollover has occurred
BAUDCON1bits.RXDTP = 0; //Receive data (RXx) is not inverted (active-high)
BAUDCON1bits.TXCKP = 0; //Idle state for transmit (TXx) is a high level
BAUDCON1bits.BRG16 = 0; //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
BAUDCON1bits.WUE = 0; //RXx pin is not monitored or the rising edge detected
BAUDCON1bits.ABDEN = 0; //Baufrate Measurement is Disable
SPBRGH1 = 0; //EUSART1 Baud Rate Generator Register High Byte
SPBRG1 = 77; //EUSART1 Baud Rate Generator Register Low Byte
//
Open1USART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,77);
/**************************Config pin I/O USART2*****************************/
ANCON0bits.PCFG0 = 1; //Setando pino AN0 (analogico) para Digital
ANCON0bits.PCFG1 = 1; //Setando pino AN1 (analogico) para Digital
TRISAbits.TRISA0 = 1;//entrada = 1
TRISAbits.TRISA1 = 0;//saida = 0
/***TX 2 Configuration************/
TXSTA2bits.CSRC = 0; //
TXSTA2bits.TX9 = 0; //Selects 8-bit transmission
TXSTA2bits.TXEN = 1; //Transmit is enabled
TXSTA2bits.SYNC = 0; //Asynchronous mode
TXSTA2bits.SENDB = 0; //dont Send Sync Break on next transmission (cleared by hardware upon completion)
TXSTA2bits.BRGH = 1; //High speed
/***RX 2 Configuration************/
RCSTA2bits.SPEN = 1; //Serial port is enabled
RCSTA2bits.RX9 = 0; //Selects 8-bit reception
RCSTA2bits.CREN = 1; //Enables the receiver
RCSTA2bits.ADDEN = 0; //Disables address detection, all bytes are received and ninth bit can be used as parity bit
/***BAUDRATE 2 Configuration************/
BAUDCON2bits.ABDOVF = 0; //No BRG rollover has occurred
BAUDCON2bits.RXDTP = 0; //Receive data (RXx) is not inverted (active-high)
BAUDCON2bits.TXCKP = 0; //Idle state for transmit (TXx) is a high level
BAUDCON2bits.BRG16 = 0; //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
BAUDCON2bits.WUE = 0; //RXx pin is not monitored or the rising edge detected
BAUDCON2bits.ABDEN = 0; //Baufrate Measurement is Disable
SPBRGH2 = 0; //EUSART2 Baud Rate Generator Register High Byte
SPBRG2 = 155; //EUSART2 Baud Rate Generator Register Low Byte
//
Open2USART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,155);
while(1){
char dado[]="";
char data[]="ATD";
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
puts1USART(data);
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
puts1USART(data);
Delay10KTCYx(200);
Delay10KTCYx(100);
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
gets2USART(dado,5);
Delay10KTCYx(200); // Delay de estabilização do circuito, tensões, etc....
Delay10KTCYx(100);
puts1USART(dado);
}
}
void main(void){
inicia();
}
#include <pps.h>
PPSUnLock();//FUNÇÃO DE REMAPEAMENTO DOS PINOS
iPPSOutput(OUT_PIN_PPS_RP1, OUT_FN_PPS_TX2CK2);//CONFIGURA O PINO TX (RP1)
iPPSInput(IN_FN_PPS_RX2DT2, IN_PIN_PPS_RP0); //CONFIGURA O PINO RX (RP0)
PPSLock();
/***TX 2 Configuration************/
TXSTA2bits.CSRC = 0; //
TXSTA2bits.TX9 = 0; //Selects 8-bit transmission
TXSTA2bits.TXEN = 1; //Transmit is enabled
TXSTA2bits.SYNC = 0; //Asynchronous mode
TXSTA2bits.SENDB = 0; //dont Send Sync Break on next transmission (cleared by hardware upon completion)
TXSTA2bits.BRGH = 1; //High speed
/***RX 2 Configuration************/
RCSTA2bits.SPEN = 1; //Serial port is enabled
RCSTA2bits.RX9 = 0; //Selects 8-bit reception
RCSTA2bits.CREN = 1; //Enables the receiver
RCSTA2bits.ADDEN = 0; //Disables address detection, all bytes are received and ninth bit can be used as parity bit
/***BAUDRATE 2 Configuration************/
BAUDCON2bits.ABDOVF = 0; //No BRG rollover has occurred
BAUDCON2bits.RXDTP = 0; //Receive data (RXx) is not inverted (active-high)
BAUDCON2bits.TXCKP = 0; //Idle state for transmit (TXx) is a high level
BAUDCON2bits.BRG16 = 0; //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
BAUDCON2bits.WUE = 0; //RXx pin is not monitored or the rising edge detected
BAUDCON2bits.ABDEN = 0; //Baufrate Measurement is Disable