Debutant, debutant en HITEC C compiler + 18f4550
Répondre à la discussion
Affichage des résultats 1 à 2 sur 2

Debutant, debutant en HITEC C compiler + 18f4550



  1. #1
    biduleur34

    Debutant, debutant en HITEC C compiler + 18f4550


    ------

    Bonjour,

    Jusqu'a maintenant je programé avec PIC basic pro compiler, mais etant trop limité je me met au C.

    Apres avoir reussi a faire clignoté des LED j'attaque quelque ch'ose d'un peu plus difficile, j'essaye de comuniqué en I2C avec un PCF8574, pour le moment la valeur a envoyer sur le bus est erroné mais peu importe...

    Mais je n'arrive meme pas a compiler mon programme.

    je me sert de la librairie de de chez Hitec.

    voici les codes:

    Code:
    #include <htc.h>
    #include "i2c.h"
    #include "delay.h"
    
    
    void main(void)
    
    {
    
    i2c_WriteTo(0xAE);	/* talk to device 1010111w */
    i2c_PutByte(0x00);	/* send data 0x00 */
    
    
    }
    Code:
    #ifndef	_I2C_H_
    #define _I2C_H_
    
    /*
     *	SDA (data) and SCL (clock) bits
     *	
     *	Special note!!!
     *	
     *	If the clock and data lines are in the same port, you will need
     *	to beware of the Read/Modify/Write issue in the PIC - since
     *	a bit set or clear on any one bit in a port will read and write
     *	back all other bits, any bits configured as input which 
     */
    
    
    /* Uncomment the next line to use the PIC's SSP Module*/
    #define I2C_MODULE 1
    
    #ifdef I2C_MODULE
    /* I2C module uses PORT C */
    #define SCL             RB1             /* clock on port B bit 1 */
    #define SCL_DIR         TRISB1
    #define SDA     		RB0             /* data on port B bit 0 */
    #define SDA_DIR         TRISB0
    #define I2CTRIS TRISB
    #define MASTER_MODE     0B1011          /* I2C firmware controlled Master Mode (slave idle) */
    #define SSPMode(val)   SSPCON1 &=0xF0; SSPCON1 |=(val & 0xf)
    
    #else
    /* Change port as required - defaults to port b */
    #define	SCL		RB2		/* clock on port B bit 2 */
    #define	SCL_DIR		TRISB2
    
    #define SDA             RB1             /* data on port B bit 1 */
    #define	SDA_DIR		TRISB1
    #define I2CTRIS TRISB
    
    #endif
    
    #define M_SDA_INP	0x02
    #define M_SDA_OUT   0xFD
    #define M_SCL_INP   0x04
    #define M_SCL_OUT	0xFB
    
    #define I2C_INPUT	1		/* data direction input */
    #define I2C_OUTPUT	0		/* data direction output */
    
    #define I2C_READ	0x01		/* read bit used with address */
    #define I2C_WRITE	0x00		/* write bit used with address */
    
    #define FALSE		0
    #define TRUE		!FALSE
    
    #define I2C_ERROR	(-1)
    #define I2C_LAST	FALSE		/* SendAck: no more bytes to send */
    #define I2C_MORE	TRUE		/* SendAck: more bytes to send */
    
    #define i2c_Start()		i2c_Restart()
    #define i2c_WriteTo(address)	i2c_Open((address), I2C_WRITE)
    #define i2c_ReadFrom(address)	i2c_Open((address), I2C_READ)
    
    #ifdef I2C_MODULE
    #define SCL_HIGH() SCL_DIR = I2C_INPUT
    #define SCL_LOW()  SCL_DIR = I2C_OUTPUT
    #define SDA_HIGH() SDA_DIR = I2C_INPUT
    #define SDA_LOW()  SDA_DIR = I2C_OUTPUT
    #else
    #define SCL_HIGH() SCL = 1; SCL_DIR = I2C_OUTPUT
    #define SCL_LOW()  SCL = 0; SCL_DIR = I2C_OUTPUT
    #define SDA_HIGH() SDA = 1; SDA_DIR = I2C_OUTPUT
    #define SDA_LOW()  SDA = 0; SDA_DIR = I2C_OUTPUT
    #endif
    
    /*
     * Timings for the i2c bus. Times are rounded up to the nearest
     * micro second.
     */
    
    #define I2C_TM_BUS_FREE		5
    #define	I2C_TM_START_SU		5
    #define I2C_TM_START_HD		4
    #define I2C_TM_SCL_LOW		5
    #define	I2C_TM_SCL_HIGH		4
    #define I2C_TM_DATA_SU		1
    #define I2C_TM_DATA_HD      0
    #define I2C_TM_SCL_TO_DATA	4	/* SCL low to data valid */
    #define	I2C_TM_STOP_SU		4
    #define I2C_TM_SCL_TMO		10	/* clock time out */
    
    extern signed char	i2c_ReadAcknowledge(void);
    extern unsigned char	i2c_SendAddress(unsigned char, unsigned char);
    extern unsigned char	i2c_SendByte(unsigned char);
    extern int		i2c_ReadByte(void);
    extern void		i2c_Restart(void);
    extern void		i2c_Stop(void);
    extern void		i2c_SendAcknowledge(unsigned char);
    extern signed char	i2c_PutByte(unsigned char);
    extern int		i2c_GetByte(unsigned char);
    extern unsigned char	i2c_Open(unsigned char, unsigned char);
    extern unsigned char	i2c_GetString(unsigned char *, unsigned char);
    extern int		i2c_PutString(const unsigned char *, unsigned char);
    extern unsigned char	i2c_WaitForSCL(void);
    extern void i2c_Free();
    #endif			/* _I2C_H_ */
    Code:
    /*
     *	Delay functions for HI-TECH C on the PIC18
     *
     *	Functions available:
     *		DelayUs(x)	Delay specified number of microseconds
     *		DelayMs(x)	Delay specified number of milliseconds
     *
     *	Note that there are range limits: 
     *	- on small values of x (i.e. x<10), the delay becomes less
     *	accurate. DelayUs is accurate with xtal frequencies in the
     * 	range of 4-16MHZ, where x must not exceed 255. 
     *	For xtal frequencies > 16MHz the valid range for DelayUs
     *	is even smaller - hence affecting DelayMs.
     *	To use DelayUs it is only necessary to include this file.
     *	To use DelayMs you must include delay.c in your project.
     *
     *	Set the crystal frequency in the CPP predefined symbols list
     *	on the PICC-18 commmand line, e.g.
     *	picc18 -D_XTAL_FREQ=4MHZ
     *
     *	or
     *	picc18 -D_XTAL_FREQ=100KHZ
     *	
     *	Note that this is the crystal frequency, the CPU clock is
     *	divided by 4.
     *
     *	MAKE SURE this code is compiled with full optimization!!!
    */
    
    #define	MHZ	*1000000
    
    #ifdef XTAL_FREQ
     // if detect old symbol, convert to new symbol and warn about name change
     #define _XTAL_FREQ XTAL_FREQ
     #warning Preprocessor symbol XTAL_FREQ has been deprecated. Now used _XTAL_FREQ.
    #endif
    
    #ifndef	_XTAL_FREQ
    #define	_XTAL_FREQ	4MHZ		/* Crystal frequency in MHz */
    #endif
    
    #if	_XTAL_FREQ < 8MHZ
    #define	uS_CNT 	238			/* 4x to make 1 mSec */
    #endif
    
    #if	_XTAL_FREQ == 8MHZ
    #define uS_CNT  244
    #endif
    
    #if	_XTAL_FREQ > 8MHZ
    #define uS_CNT  246
    #endif
    
    #define FREQ_MULT	(_XTAL_FREQ)/(4MHZ)
    
    #define	DelayUs(x)	{ unsigned char _dcnt; \
    			  if(x>=4) \
    				_dcnt=(x*(FREQ_MULT)/5); \
    			  else \
    				_dcnt=1; \
    			  while(--_dcnt > 0){ \
    					asm("bra $+1");\
    					continue;\
    			  }\
    			} 
    
    // This routine is now deprecated - now #include htc.h and use __delay_ms() instead.
    extern void DelayMs(unsigned char);
    Et voici l'erreur a la compilation.

    Code:
    Build C:\ELECTRONIQUE\PROJET MPLAB\18f4550 es1\test18f4550 for device 18F4550
    Using driver C:\Program Files\HI-TECH Software\PICC-18\9.80\bin\picc18.exe
    
    Make: The target "C:\ELECTRONIQUE\PROJET MPLAB\18f4550 es1\main.p1" is out of date.
    Executing: "C:\Program Files\HI-TECH Software\PICC-18\9.80\bin\picc18.exe" --pass1 "C:\ELECTRONIQUE\PROJET MPLAB\18f4550 es1\main.c" -q --chip=18F4550 -P --runtime=default,+init,-keep,-download,-stackwarn,-config,+clib,-plib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 -Blarge --double=24 --float=24 --cp=16 --addrqual=ignore -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
    Executing: "C:\Program Files\HI-TECH Software\PICC-18\9.80\bin\picc18.exe" -otest18f4550.cof -mtest18f4550.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 main.p1 --chip=18F4550 -P --runtime=default,+init,-keep,-download,-stackwarn,-config,+clib,-plib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 -Blarge --double=24 --float=24 --cp=16 --addrqual=ignore -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
    Licensed for evaluation purposes only.
    This licence will expire on Thu, 19 Jul 2012.
    HI-TECH C Compiler for PIC18 MCUs (PRO Mode)  V9.80
    Copyright (C) 2011 Microchip Technology Inc.
    Advisory[1233] Employing 18F4550 errata work-arounds:
    Advisory[1234]  * Corrupted fast interrupt shadow registers
    Error   [500] ; 0. undefined symbols:
    	_i2c_PutByte(test18f4550.obj) _i2c_Open(test18f4550.obj) 
    
    ********** Build failed! **********
    comme vous pouvez le voir je bute vraiment a la premiere etape, j'ai le datasheet sous les yeux, mais je ne sais pas ou chercher.

    merci

    -----
    Dernière modification par biduleur34 ; 28/05/2012 à 16h14.

  2. #2
    biduleur34

    Re : Debutant, debutant en HITEC C compiler + 18f4550

    En fait pour resumer le soucis que j'ai ce trouve apparement avec les routines i2c_PutByte et I2c_open qui ne sont pas trouver: undefined symbol.

    Code:
    extern signed char	i2c_PutByte(unsigned char);
    present a la fin de i2c.h

    je ne comprend pas pourquoi il ne les trouvent pas..

    merci.
    Dernière modification par biduleur34 ; 28/05/2012 à 18h09.

Discussions similaires

  1. Un débutant de plus !
    Par invite63cfe518 dans le forum Matériel astronomique et photos d'amateurs
    Réponses: 6
    Dernier message: 27/12/2011, 22h36
  2. help debutant en C
    Par invite201f4c83 dans le forum Programmation et langages, Algorithmique
    Réponses: 3
    Dernier message: 25/03/2011, 21h59
  3. Réponses: 4
    Dernier message: 12/03/2011, 16h13
  4. Tout petit problème de débutant avec Hi Tech C Compiler
    Par invite7e727e46 dans le forum Électronique
    Réponses: 2
    Dernier message: 05/06/2010, 11h07
  5. débutant en VB
    Par invite5ef05993 dans le forum Logiciel - Software - Open Source
    Réponses: 4
    Dernier message: 03/04/2007, 12h55
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...