nick703
Advanced Member level 1
- Joined
- Oct 17, 2011
- Messages
- 422
- Helped
- 21
- Reputation
- 44
- Reaction score
- 22
- Trophy points
- 1,298
- Location
- surat
- Activity points
- 3,987
hello friends i have using pic18f4431 and c18 microchip library . now i want to receive string and particular char from pc via serial port ok . so here is my receive and transmit function
SO how to receive string using serial port ? any code may be help ?
Code:
#pragma code IntrruptPriorityHigh = 0x08
void IntrruptPriorityHigh(void){
_asm goto IntrruptHandleHigh _endasm
}
#pragma code
#pragma interrupt IntrruptHandleHigh
void IntrruptHandleHigh(void){
if(PIR1bits.RCIF == 1)
{
PORTAbits.RA1 = 0; //Communication LED ON
C[i] = RCREG; //ReadUSART();
i++;
if(i > 15)
{i = 0;j = 0;}
PIR1bits.RCIF = 0;
}
}
#pragma code IntrruptPriorityLow = 0x18
void IntrruptPriorityLow(void){}
void Transmit(char* pstring)
{
a = 0;
i = 0;
j = 0;
while(*pstring != '\0')
{
while(!(TXSTA & 0x02));
TXREG = *pstring;
pstring ++;
C[a] = 0;
a++;
C[a] = 0;
a++;
}
}
void initial_all(void)
{
BAUDCTL = 0x08; //Baud rate control bits
SPBRG = 0x03; //load Baud Rate Generator Registers
SPBRGH = 0x01;
TXSTA = 0xA4; //Initialize USART Async. transmitter
RCSTA = 0x90; //initialize USART Async. receiver
T1CON = 0x00; //TIMER 1 CONTROL REGISTER SET
TMR1H = 0xC5 ; //TIMER0_HIGH;
TMR1L = 0x62 ; // TIMER0_LOW;
T0CON = 0x08;
TMR0H = 0x3D; // TIMER 0 LOAD FOR 10 mS
TMR0L = 0xCD;
TRISC = 0x89;
TRISD = 0x01;
PTCON1bits.PTEN = TRUE;
}
void initial_intrrupt(void){
RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
// PIE1bits.ADIE = TRUE; //ADC INTRUPT ENABLE
// IPR1bits.ADIP = 0;
PIE1bits.RCIE = TRUE; //Enable receiver intrrupt
IPR1bits.RCIP = 1;
PIE1bits.TMR1IE = TRUE; //TIMER INTRRUPT ENABLE
IPR1bits.TMR1IP = 0; //PRIORITY LOW
INTCONbits.TMR0IE = 1; //TIMER 0 INTRRUPT ENABLE
INTCON2bits.TMR0IP = 0; //PRIORITY LOW
}
char PowerOn[9] = {"[TEST]"};
unsigned char C[15];
void main()
{
initial_all();
initial_intrrupt();
initial_start();
T0CONbits.TMR0ON = TRUE; // TIMER 0 ON
Transmit(PowerOn);
while(1)
{
}
}
SO how to receive string using serial port ? any code may be help ?