Page 1 of 1

PIC16F887+UC00A*Urgent*

PostPosted: Wed Apr 16, 2014 9:01 pm
by wazier
Hi there!
I really2 need help here.
I am now developing a system by using the PIC16F887 MCU. I am planning to use the UC00A to interface with the PC. But previously I was mistakenly connecting the UC00A's Rx and Tx port to the PIC16F887's Rx and Tx ports respectively. After discovering that mistakes, I've changed the terminal connection by reversing them. Now I am able to send the string through the hyperterminal and display it on the LCD. But, I am unable to receive any string sent by the MCU to the terminal. The UC00A is not even blinking for the Rx signal. Only the Tx LED is blinking if string was typed into the hyperterminal and sent to the MCU. Is there any chance that I've already break my UC00A due to my previous mistake? I am using the Cytron's Project 13 to test them out.
Compiler: Hi-Tech C v9.83
MPLAB 8.84

Any help and feedback is much appreciated.

Re: PIC16F887+UC00A*Urgent*

PostPosted: Thu Apr 17, 2014 9:29 am
by Idris
Hi wazier,

Are you sure the microcontroller really send the UART data to UC00A - PC?
It is hard to broke the UC00A by this mistake. Maybe you can share your program here.

Re: PIC16F887+UC00A*Urgent*

PostPosted: Thu Apr 17, 2014 12:57 pm
by wazier
Hi Idris,
The codes are as follows:
CODE: SELECT_ALL_CODE
#include <htc.h>
#include "lcd.h"
#include "system.h"
#include "uart.h"

//   Configuration
//==========================================================================
__CONFIG ( 0x2FF2 );                        // Configuration for PIC16F887 at 2007
__CONFIG ( 0x3FFF );                        // Configuration for PIC16F887 at 2008

void delay(unsigned int ui_value)
{
   while (ui_value-- > 0)
   {
      __delay_ms(1);      // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
   }   
}

//   main function
//==========================================================================
void main(void)
{
   PORTA = 0;                              // Clear Port
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;

   TRISA = 0b00000000;                        // set PORTA as INPUT
   TRISB = 0b00000011;                        // set PORTB<7:2> as OUTPUT , PORTB<1:0> as INPUT
   TRISC = 0b11000000;
   TRISD = 0b00000000;                        // set PORTD as output
      
   ANSELH = 0;                            // SET PORTB as DIGITAL I/O for PIC16F887

   uart_initialize();                        // Initialise UART
   delay(500);

   lcd_initialize();                        // Initialise LCD

// send signal to Hyperterminal to tell the SK40C is ready
   lcd_putstr("Ready To Receive & Transmit!!");
   delay(2000);
   lcd_clear();
   uart_putstr("Ready To Receive & Transmit!!");
   delay(1200);

// receive data from HyperTerminal by pressing PC keyboard
while (1)
   {
   unsigned int data,i = 0;
   for (i=0 ; i<32 ; i++)                        // LCD have 32 display spaces
      {
      if(i == 15)lcd_2ndline();                  // if more then 0x0F,jump to 2nd line
      else if (i == 31)lcd_home();               // if more then 0x4F, jump to 1st line

         uc_uart_receive();                     // UART receive data   
         data = RCREG;                        // receive data from uart and save at data
         send_lcd_data(1,data);                  // data the data to LCD display
      }
   }
}   


While in the uart.c are some codes as follows:
CODE: SELECT_ALL_CODE
#include <htc.h>
#include "system.h"
#include "uart.h"



/*******************************************************************************
* PUBLIC FUNCTION: uart_initialize
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the UART module.
*
*******************************************************************************/
void uart_initialize(void)
{
   unsigned char dummy = 0;
   BRG16 = 0;
   SYNC = 0;
   TX9 = 0;
   RX9 = 0;
   BRGH = 1;                           // Select high speed baud rate.
   SPBRG = 129;                        // Configure the baud rate.
   SPEN = 1;                           // Enable serial port.
   CREN = 1;                           // Enable reception.
   TXEN = 1;                           // Enable transmission.
   TXIE = 0;
   RCIE = 1;
   dummy = RCREG;                        // dummy read, to clear the receive buffer
   dummy = RCREG;
}



/*******************************************************************************
* PUBLIC FUNCTION: uart_transmit
*
* PARAMETERS:
* ~ uc_data      - The data that we want to transmit.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* This function will transmit one byte of data using UART. This is a blocking
* function, if the transmit buffer is full, we will wait until the
* data in the buffer has been sent out before we move in the new data.
*
*******************************************************************************/
void uart_transmit(unsigned char uc_data)
{
   // Wait until the transmit buffer is ready for new data.
   while (TXIF == 0);
   
   // Transmit the data.
   TXREG = uc_data;
}



/*******************************************************************************
* PUBLIC FUNCTION: uc_uart_receive
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ The data received from the UART.
*
* DESCRIPTIONS:
* This function will receive one byte of data using UART. This is a blocking
* function because if the receive buffer is empty, we will wait until the
* data is received.
*
*******************************************************************************/
unsigned char uc_uart_receive(void)
{
   // If there is overrun error...
   if (OERR == 1) {
      // Clear the flag by disable and enable back the reception.
      CREN = 0;
      CREN = 1;
   }   
   
   // Wait until there is data available in the receive buffer.
   while (RCIF == 0);
   
   // Return the received data.
   return RCREG;
}



/*******************************************************************************
* PUBLIC FUNCTION: uart_putstr
*
* PARAMETERS:
* ~ csz_string   - The null terminated string to transmit.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Transmit a string using the UART.
*
*******************************************************************************/
void uart_putstr(const char* csz_string)
{
   // Loop until the end of string.
   while (*csz_string != '\0') {
      uart_transmit(*csz_string);
         
      // Point to next character.
      csz_string++;
   }
}



Luckily I have discovered to ensure the communication between the MCU and my PC. Each of them can send and receive strings now. But there is another problem. I cannot remove my ICSP programmer from the board and PCeven though I am not using it. I have to keep them connected. Otherwise, the MCU acan only receive the strings from ny PC while the MCU cannot send any string to my PC through the UC00A.
How can this even happening? The pins are not even related to each other. To program the MCU, it needs RB6 and RB7 ports. While for the UART, it will only needs RC6 and RC7.
Can you suggest me something?

Re: PIC16F887+UC00A*Urgent*

PostPosted: Thu Apr 17, 2014 1:05 pm
by wazier
And FYI, I don't include any power supply from the ICSP programmer to my board. I have removed them entirely. The inputs from the ICSP to my board is purely RB6, RB7 and MCLR. So, in order to program my MCU, I have to power it on from the external source. So far, no problem with that. But when it comes to the UART, this problem occurs. I am confused, what is causinh this. Why does it needs my ICSP to be attached to it and connected to the PC to ensure it is able to run properly. The supply from the ICSP is not even there because I have removed it. Is there any chance that my PIC16F887 break already?

Re: PIC16F887+UC00A*Urgent*

PostPosted: Fri Apr 18, 2014 10:23 am
by Idris
In your program, try to set RC6 (transmit pin) as output.

e.g: TRISC = 0b10000000;

Re: PIC16F887+UC00A*Urgent*

PostPosted: Fri Apr 18, 2014 9:05 pm
by ober
wazier WROTE:And FYI, I don't include any power supply from the ICSP programmer to my board. I have removed them entirely. The inputs from the ICSP to my board is purely RB6, RB7 and MCLR. So, in order to program my MCU, I have to power it on from the external source. So far, no problem with that. But when it comes to the UART, this problem occurs. I am confused, what is causinh this. Why does it needs my ICSP to be attached to it and connected to the PC to ensure it is able to run properly. The supply from the ICSP is not even there because I have removed it. Is there any chance that my PIC16F887 break already?


How about the GND pin? Is it being connected to ICSP and UC00A too?