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 void main() { char a[2]; int i; OSCCON =0b01100000; TRISCbits.TRISC6 = 0; // set TX (RC6) as output TRISCbits.TRISC7 = 1; // and RX (RC7) as input OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_SINGLE_RX & USART_BRGH_HIGH, 51);// baude rate 9.6 putrsUSART( "\n hallooooooo " ); Delay10KTCYx(200); //putrsUSART( "\r\nPlease Enter your Name\n" ); while (1){ // write to the USART putrsUSART("Type 2 chars: "); // while(BusyUSART()); // wait for input while (!DataRdyUSART()); // get 2 chars and put in inputstr getsUSART(a, 2); putrsUSART("\r\nYou typed: "); putsUSART(a); putrsUSART("\r\n"); } }
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 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 = 0; //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; //EUSART2 Baud Rate Generator Register High Byte
SPBRG1 = 51; //EUSART2 Baud Rate Generator Register Low Byte
//
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_SINGLE_RX & USART_BRGH_HIGH, 51);// baude rate 9.6
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 void main() { char a; OSCCON =0b01100000; TRISCbits.TRISC6 = 0; TRISCbits.TRISC7 = 1; /***TX Configuration************/ TXSTAbits.CSRC = 0; // TXSTAbits.TX9 = 0; //Selects 8-bit transmission TXSTAbits.TXEN = 1; //Transmit is enabled TXSTAbits.SYNC = 0; //Asynchronous mode TXSTAbits.SENDB = 0; //dont Send Sync Break on next transmission (cleared by hardware upon completion) TXSTAbits.BRGH = 1; //High speed /***RX Configuration************/ RCSTAbits.SPEN = 1; //Serial port is enabled RCSTAbits.RX9 = 0; //Selects 8-bit reception RCSTAbits.CREN = 1; //Enables the receiver RCSTAbits.ADDEN = 0; //Disables address detection, all bytes are received and ninth bit can be used as parity bit /***BAUDRATE Configuration************/ BAUDCTLbits.ABDOVF = 0; //No BRG rollover has occurred BAUDCTLbits.DTRXP = 0; //Receive data (RXx) is not inverted (active-high) BAUDCTLbits.CKTXP = 0; //Idle state for transmit (TXx) is a high level BAUDCTLbits.BRG16 = 0; //8-bit Baud Rate Generator – SPBRGHx and SPBRGx BAUDCTLbits.WUE = 0; //RXx pin is not monitored or the rising edge detected BAUDCTLbits.ABDEN = 0; //Baufrate Measurement is Disable SPBRGH = 0; //EUSART2 Baud Rate Generator Register High Byte SPBRG = 51; //EUSART2 Baud Rate Generator Register Low Byte printf("hallooo"); // write to the USART putrsUSART("Type 2 chars: "); while(BusyUSART()); // wait for input // while (!DataRdyUSART()); // get 2 chars and put in inputstr // getsUSART(a, 2); a=getcUSART(); putrsUSART("\r\nYou typed: "); putsUSART(a); putrsUSART("\r\n"); while(1); }
if(PIR1bits.RC1IF == 1)
{
a = RCREG1;
}
TXREG1 =a;
//03/07/2012
//TEST ok en lecture
#include "p18f46k22.h"
#include "stdio.h"
#include <stdlib.h>
#include <delays.h>
#include <string.h>
#include <usart.h> // pour fonctions UART HARDWARE
#include <adc.h>
#include <ctype.h>
#include <portb.h>
#include <timers.h>
#include <math.h>
// configuration bits set in code !
#ifdef OSCILLATEUR_INTERNE
#pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF
#else
#pragma config FOSC = HSHP, PLLCFG=OFF, PRICLKEN=ON ,FCMEN=OFF
#endif
#pragma config IESO=OFF,PWRTEN=ON,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1
#pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
#pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
#pragma config EBTRB = OFF
// config vue sur Pickit3 : 25FF 3F1F BFFF FF85 C00F E00F 400F
#ifndef Byte
#define Byte unsigned char
#endif
#define DureeCycle 10 // * 1 diziemes de secondes => 1,0sec
#define CLS 12
#define BS 8
#define TAB 9
#define CR 13
#define LF 10
#define Bell 7
#define ON 0 // logique inverse avec led tiree au +5V
#define OFF 1
#define MAX_LEN 80
unsigned int i,j,k;
unsigned int dummy;
unsigned int j1;
unsigned int M;
unsigned int BRG_REG;
volatile int i1;
volatile char c1;
volatile int count;
long L;
char Texte[MAX_LEN]="18F46K22 test RS232 C18\r\n 19200bds Quartz 10Mhz \r\n\0";
char *txt=&Texte[0];
char F[9]="00000000"; // maxi 20MHz "4294967296";
unsigned char Entree[17]="1234567890123456";
unsigned char *valtxt;
char buffer[MAX_LEN]="00000000000000000000000"; // buffer de reception
char received;
char *ptlec; // pointeur de lecture
char *ptecr; // pointeur d'ecriture
unsigned int CptCars;
unsigned int SaisieOk;
struct chbits { // 8 flags
unsigned FrameErr:1;
unsigned Over:1;
unsigned Elligible:1;
unsigned Togle:1;
unsigned Blc:1;
unsigned standby:1;
unsigned Fill:1;
unsigned Lcd:1;
}Drapeaux ;
union
{ unsigned char Fanion;
struct chbits Drapeaux ;
} Flags;
#define OUT_RS232 Drapeaux.Lcd=0;
#define OUT_LCD Drapeaux.Lcd=1;
//--------- RS232 UART HARDWARE --------------
void Init_UART1(void);
int PutStr_RS(char *s);
void Put_RS(char * untel);
void CRLF();
void Write_Word(unsigned int M,char Sign);
void Tempo(long val);
void Remplis_N_blancs(Byte N);
void Init_Hardware(void) ;
void InterruptHandlerHigh (void);
//gestionnaire d'interruption
//------------------------------
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
// High priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
static char i ; // doit ętre statique pour conserver sa valeur entre les IT
char C ;
//======== SERIAL======================
if(PIR1bits.RCIF) // si un car arrive
{
C =Read1USART(); // le lire => RAZ RCIF
if(RCSTAbits.FERR || RCSTAbits.OERR)
{
RCSTAbits.CREN = 0 ; RCSTAbits.CREN= 1 ;
}
while(Busy1USART()); // par sécurité
if (PORTBbits.RB1==0) Write1USART(C); // echo
if( C == BS)
{
if(i>0){
i--; }
}
else
{
if(C != CR && i<MAX_LEN)
{
buffer[i++]=C ; // stockage
}else
{
buffer[i]='\0'; // fin de chaîne si CR
i=0;
received =1;
}
}
}
} // fin de routine interrupts
void Init_UART1(void)
{
// USART_BRGH_HIGH,32
// init 38400Bd a 20Mhz
// init 19200Bd a 10Mhz avec IT en rx
// voir para 18.5 spec sheet DS41159B page 186
Open1USART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,32
);
INTCONbits.PEIE = 0 ; // autorisation des IT des périphériques
INTCONbits.GIE = 0 ; // autorisation globale des IT
}
int PutStr_RS(char *s)
{
int n;
for (n = 0; *s; n++, s++)
{
Put_RS(*s);
}
return n;
}
void Put_RS(char * untel)
{
while(Busy1USART());
Write1USART(untel);
}
void CRLF()
{
Put_RS(CR); Put_RS(LF);
}
void Tempo(long val)
{
while(val>0){val--;}
}
void main()
{
char a;
//OSCCON =0b01100000;
ANSELC=0;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 1;
Init_UART1();
Put_RS(CLS); // clear Vbray terminal Screen
Tempo(150000L);
// init pour interruptions ----
INTCONbits.GIE = 1; // active global interrupt
INTCONbits.GIEL=1;
RCSTA1bits.CREN= 1 ;
PIE1bits.RC1IE = 1;
INTCONbits.PEIE = 1; // autorisation des IT des périphériques
buffer[0]=0;
received=0;
;
k=PutStr_RS(txt);
printf("hallooo\r\n");
// write to the USART
printf("Type some chars and CR to send them: ");
while(1)
{
if (received==1) // test if reception occured
{
j=0;
printf("\r\nYou typed: ");
while (buffer[j]!=0)
{
a=buffer[j];
Put_RS(a);
j++;
Tempo(1000L); // you can remove it
}
received=0;
buffer[0]=0;
}
Tempo(15000L); // you can remove it
}
}
/* results on Vbray terminal
18F46K22 test RS232 C18
19200bds Quartz 10Mhz
hallooo
Type some chars and CR to send them:
You typed: 00001
You typed: 00010
You typed: 00100
You typed: 01000
You typed: 05000
You typed: 10000
You typed: 15000
You typed: 20000
You typed: 21000
You typed: S
You typed: C
You typed: T
You typed: D
You typed: R
You typed: X
You typed: How are you
*/
//https://www.edaboard.com/threads/258142/
//05/07/2012
// avec Pickit3
// TEST OK if less than 3 cars collapsed
// because of FIFO size=3 on 18F46K22
#include "p18f46k22.h"
#include "stdio.h"
#include <stdlib.h>
#include <delays.h>
#include <string.h>
#include <usart.h> // pour fonctions UART HARDWARE
#include <ctype.h>
#include <portb.h>
// configuration bits set in code !
#ifdef OSCILLATEUR_INTERNE
#pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF
#else
#pragma config FOSC = HSHP, PLLCFG=OFF, PRICLKEN=ON ,FCMEN=OFF
#endif
#pragma config IESO=OFF,PWRTEN=ON,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1
#pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
#pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
#pragma config EBTRB = OFF
// config vue sur Pickit3 : 2200 3C18 9900 0084 C00F E00F 400F
#ifndef Byte
#define Byte unsigned char
#endif
#define CLS 12
#define TAB 9
#define CR 13
#define LF 10
#define Led_Rouge PORTAbits.RA4
#define Allume 0
#define Eteint 1
unsigned int i,j,k;
volatile int count;
long L;
//--------- RS232 UART HARDWARE --------------
void Init_UART1(void);
int PutStr_RS(char *s);
void Put_RS(char * untel);
void CRLF();
void Tempo(long val);
void Init_UART1(void)
{
// USART_BRGH_HIGH,32
// init 38400Bd a 20Mhz
// init 19200Bd a 10Mhz avec IT en rx
// voir para 18.5 spec sheet DS41159B page 186
Open1USART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,32
);
INTCONbits.PEIE = 0 ; // autorisation des IT des périphériques
INTCONbits.GIE = 0 ; // autorisation globale des IT
}
int PutStr_RS(char *s)
{
int n;
for (n = 0; *s; n++, s++)
{
Put_RS(*s);
}
return n;
}
void Put_RS(char * untel)
{
while(Busy1USART());
Write1USART(untel);
}
void CRLF()
{
Put_RS(CR); Put_RS(LF);
}
void Tempo(long val)
{
while(val>0){val--;}
}
void main()
{
char a;
unsigned char d;
//OSCCON =0b01100000;
ANSELA=0;
TRISA = 0b00001111 ;
TRISAbits.TRISA4 = 0; // led rouge
LATA = 0x00;
ANSELC=0;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 1;
Led_Rouge=Allume;
Init_UART1();
Put_RS(CLS); // clear Vbray terminal Screen
Tempo(100000L);
// init pour interruptions ----
INTCONbits.GIE = 0; // active global interrupt
INTCONbits.GIEL=0;
RCSTA1bits.CREN= 1 ;
PIE1bits.RC1IE = 0;
INTCONbits.PEIE = 1; // autorisation des IT des périphériques
CRLF();
printf("hallooo\r\n");
// write to the USART
printf("Type some chars and CR to send them: ");
while(1)
{
if(PIR1bits.RCIF) // si un car arrive
{
a =Read1USART(); // le lire => RAZ RCIF
Led_Rouge=Allume;
printf("\r\nYou typed: ");
Put_RS(a);
}
// test if Overrun occured !
if (RCSTA1bits.OERR==1) Led_Rouge=Allume; else Led_Rouge=Eteint;
}
}
/*
hallooo
Type some chars and CR to send them:
You typed: C 2 cars C + CR => ok
You typed:
You typed: R 2 cars R + CR => ok
You typed:
You typed: X 2 cars X + CR => ok
You typed:
You typed: T 1 car --> OK
You typed: V 1 car --> ok
You typed: 0 number 0001 => Overrun => led allways ON
You typed: 0
You typed: 0
*/
// init part
char Texte[MAX_LEN]="18F46K22 test simple RS b en MPLAB C18\r\n 05/07/2012 rev a\n\r19200bds Quartz 10Mhz \r\n\0";
char *txt=&Texte[0];
// main part
void main()
{
...
while(1)
{
txt=&Texte[0]; // init buffer
Texte[0]=0;
if(PIR1bits.RCIF) // si un car est arrive
{
gets1USART(txt,6); // attend la reception de 6 cars
Led_Rouge=Allume;
printf("\r\nYou typed: ");
Texte[6]=0; // rajout terminateur de string
PutStr_RS(txt);
}
// test if Overrun occured !
if (RCSTA1bits.OERR==1) Led_Rouge=Allume; else Led_Rouge=Eteint;
}
}
unsigned char a;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 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 = 0; //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; //EUSART2 Baud Rate Generator Register High Byte
SPBRG1 = 51; //EUSART2 Baud Rate Generator Register Low Byte
while(1)
{
if(PIR1bits.RC1IF == 1)
{
a = RCREG1; //receives character in a
TXREG1 =a; //echo transmits the same character
}
}
does this mean the mistake is in any of my settings...
# pragma config FOSC=INTIO67
# pragma config WDTEN = OFF
# pragma config LVP = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 #include <p18f45k20.h> #include "stdio.h" #include <stdlib.h> #include <delays.h> #include <string.h> #include <usart.h> // pour fonctions UART HARDWARE #include <ctype.h> #include <portb.h> # pragma config FOSC=INTIO67 # pragma config WDTEN = OFF # pragma config LVP = OFF #pragma config PWRT = OFF #pragma config BOREN = OFF #pragma config MCLRE = OFF #pragma config PBADEN = OFF #ifndef Byte #define Byte unsigned char #endif #define CLS 12 #define TAB 9 #define CR 13 #define LF 10 #define Led_Rouge PORTAbits.RA4 #define Allume 0 #define Eteint 1 unsigned int i,j,k; volatile int count; long L; //--------- RS232 UART HARDWARE -------------- void Init_UART1(void); int PutStr_RS(char *s); void Put_RS(char * untel); void CRLF(); void Tempo(long val); void Init_UART1(void) { OpenUSART( USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH,51 ); INTCONbits.PEIE = 0 ; // autorisation des IT des périphériques INTCONbits.GIE = 0 ; // autorisation globale des IT } int PutStr_RS(char *s) { int n; for (n = 0; *s; n++, s++) { Put_RS(*s); } return n; } void Put_RS(char * untel) { while(BusyUSART()); WriteUSART(untel); } void CRLF() { Put_RS(CR); Put_RS(LF); } void Tempo(long val) { while(val>0){val--;} } void main() { char a; unsigned char d; OSCCON =0b01100000; //ANSELA=0; TRISA = 0b00001111 ; TRISAbits.TRISA4 = 0; // led rouge LATA = 0x00; //ANSELC=0; TRISCbits.TRISC6 = 0; TRISCbits.TRISC7 = 1; Led_Rouge=Allume; Init_UART1(); Put_RS(CLS); // clear Vbray terminal Screen Tempo(100000L); // init pour interruptions ---- INTCONbits.GIE = 0; // active global interrupt INTCONbits.GIEL=0; RCSTAbits.CREN= 1 ; PIE1bits.RCIE = 0; INTCONbits.PEIE = 1; // autorisation des IT des périphériques CRLF(); printf("hallooo\r\n"); // write to the USART printf("Type some chars and CR to send them: "); while(1) { if(PIR1bits.RCIF) // si un car arrive { a =ReadUSART(); // le lire => RAZ RCIF Led_Rouge=Allume; printf("\r\nYou typed: "); Put_RS(a); } // test if Overrun occured ! if (RCSTAbits.OERR==1) Led_Rouge=Allume; else Led_Rouge=Eteint; } }
if(PIR1bits.RC1IF == 1)
can we pass a string without using interrupt?
it didn't work also in my configuration.shreyas_patel21
//https://www.edaboard.com/threads/258142/
// Re: USART reception in c18
//07/07/2012
// avec Pickit3
// reception et echo d'un car
#include "p18f46k22.h"
#include "stdio.h"
#include <stdlib.h>
#include <delays.h>
#include <string.h>
#include <usart.h> // pour fonctions UART HARDWARE
#include <ctype.h>
#include <portb.h>
// configuration bits set in code !
#ifdef OSCILLATEUR_INTERNE
#pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF
#else
#pragma config FOSC = HSHP, PLLCFG=OFF, PRICLKEN=ON ,FCMEN=OFF
#endif
#pragma config IESO=OFF,PWRTEN=ON,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1
#pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
#pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
#pragma config CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
#pragma config EBTRB = OFF
// config vue sur Pickit3 :
void Put_RS(char * untel)
{
while(Busy1USART());
Write1USART(untel);
}
// ---------------------------------------------
//https://www.edaboard.com/threads/258142/
//shreyas_patel21
void main()
{
unsigned char a;
ANSELC=0;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC7 = 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
TXSTA1bits.BRGH = 0; //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
/***BAUDRATE Configuration************/
BAUDCON1bits.ABDOVF = 0; //No BRG rollover has occurred
// 2 lines commented because error compil generation
// 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 = 16; //EUSART1 Baud Rate Generator Register Low Byte 9600bauds Q=10Mhz
Put_RS('H');
Put_RS('E');
Put_RS('L');
Put_RS('L');
Put_RS('O');
Put_RS(10);
Put_RS(13);
while(1)
{
if(PIR1bits.RC1IF == 1)
{
Put_RS('*'); //yes! i get it
a = RCREG1; //receives character in a
Put_RS(a); //echo transmits the same character
}
}
}
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?