- #1
whatry109
- 3
- 1
Homework Statement
Hello~
When using the serial port sends data,the Configuration function in the serial port and the sending function were put in the .C document of mian function.The serial port can send strings normally,but when I put them into another .C ,the serial port just can send a part of strings.(the begin and the end) I don’t understand why? Can you help me?
This is my origin code:
Code:
/A serial port initialization
void Usart1_Init()
{
TRISC7 = 1;
TRISC6 = 0;
//TXSTAx:Sending states and controlling register
TXSTA1bits.TX9 = 0; //choosing eight number to send
TXSTA1bits.TXEN = 1; //enabled sending
TXSTA1bits.SYNC = 0; //asynchronous mode
TXSTA1bits.BRGH = 1; //High speed mode
//RCSTAx:receive states and controlling register
RCSTA1bits.SPEN = 1; //enabled seriel port
RCSTA1bits.RX9 = 0; //choosing eight number to receive
RCSTA1bits.CREN = 1; //0=baned receiver ,1= allowing receiver
RC1IE = 1; //receiving the interruption
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
RC1IF = 0;
//BAUDCONx:register is controlled by Baud rate
BAUDCON1bits.BRG16 = 1; // 16 number of Baud rate ―SPBRGHx 和 SPBRGx
SPBRG = 95; //Baud rater
19200pbs
}
//the serial port send the first byte data
void Usart1_Send_Byte(char dat)
{
TXREG1 = dat;
while(!TXSTA2bits.TRMT);
}//the serial port send the Hexadecimal array
void Usart1_Send_Array(char array[],char n)
{
unsigned char i=0;
for(i = 0; i < n; i ++)
{
Usart1_Send_Byte(array[i]);
__delay_us(500);
}
}
//the serial port send the string data
void Usart1_Send_String(char *str)
{
while(*str != '\0')
{
Usart1_Send_Byte(*str++);
__delay_us(500);
}
}//******************************
Homework Equations
This is the PIC18F67K22's datasheet.Please have a look if needed.
The Attempt at a Solution
I have adjusted it and I found that “oid Usart1_Send_Byte(char dat)” has no influence at anywherejust this two function of sending (void Usart1_Send_String(F6ar *str)和void Usart1_Send_Array(char array[],char n))can’t operate!
Thank you in advance!
Last edited by a moderator: