Hitech C compile problem

Status
Not open for further replies.

Thiliniv

Junior Member level 3
Joined
Nov 20, 2009
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,458
I hav written a code in MPLAB and compiled it usin Hitech C. Though I searched internet also I couln't find the solution. attached here is my code and the error message.
Anybody pls help me ASAP.


Code:
#include <stdio.h>
#include <htc.h>
#include "usart.h"

/* A simple demonstration of serial communications which
 * incorporates the on-board hardware USART of the Microchip
 * PIC16Fxxx series of devices. */

void main(void){
	unsigned char input;

	INTCON=0;	// purpose of disabling the interrupts.

	init_comms();	// set up the USART - settings defined in usart.h

	// Output a message to prompt the user for a keypress	
	printf("\rPress a key and I will echo it back:\n");
	while(1){
		input = getch();	// read a response from the user
		printf("\rI detected [%c]",input);	// echo it back
	}
}


Error msg I'm getting,

Error [500] ; 0. undefined symbols:
_getch(pwnw.obj) _putch(pwnw.obj)

********** Build failed! **********
 

The functions in stdio.h are "putchar()" and "getchar()" while you are using "getch()" and "putch()" which in my opinion is wrong. See the documentation of HI-TECH compiler.
Moreover you will have to initilize the serial port to the desired baud rate in order to use these functions on a real embedded system.

Hope this solves your problem.
Regards.
 

But I'm including " #include "usart.h" " also . "getch()" and "putch()" are defined there. Any idea??????

Added after 1 hours 55 minutes:

hello waseem ,
I modified the code as you said, But the problem still remains. Any idea?

Code:
#include <stdio.h> 
#include <htc.h> 
#include "usart.h" 

#define BAUD_RATE 9600
/* A simple demonstration of serial communications which 
 * incorporates the on-board hardware USART of the Microchip 
 * PIC16Fxxx series of devices. */ 

void main(void){ 
   unsigned char input; 

   INTCON=0;   // purpose of disabling the interrupts. 

   init_comms();   // set up the USART - settings defined in usart.h 

   // Output a message to prompt the user for a keypress    
   printf("\rPress a key and I will echo it back:\n"); 
   while(1){ 
      input = getchar();   // read a response from the user 
      printf("\rI detected [%c]",input);   // echo it back 
   } 
}


ERROR msg,
Licensed for evaluation purposes only.
This licence will expire on Tue, 27 Jul 2010.
HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.70
Copyright (C) 2009 Microchip Technology Inc.
Error [500] ; 0. undefined symbols:
_putch(pwnw.obj) _getche(pwnw.obj)

********** Build failed! **********
 

You have to link with the right libraries I guess.
--
Amr
 

Here is a complete project with Proteus model that i have written for you in HI-TECH C. Simulate it and understand it.

Regards.
 
Reactions: picprog

    Thiliniv

    Points: 2
    Helpful Answer Positive Rating

    picprog

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…