The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 06:31:43 06:31


Login with username, password and session length


Pages: [1]
Print
Author Topic: Hi-Tech drivers  (Read 8963 times)
0 Members and 1 Guest are viewing this topic.
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« on: February 17, 2008, 08:03:11 08:03 »

I would like to start this topic to help us in use a professional compiler. Here everybody can contribute in making drivers for HiTech compilers. I will start with eeprom drivers, but first some type definitions.
File "types.h", this file I use for inter-compiler compatibility, these definitions are used only for Hi-Tech:
Code:
#ifndef _types_h_
#define _types_h_

typedef unsigned char U8;
typedef signed char S8;
typedef unsigned int U16;
typedef signed int S16;
typedef unsigned long U32;
typedef signed long S32;

typedef enum
{
false = 0,
true = 1
}
BOOL;

#endif //_types_h_

Now the eeprom driver.
File "Eeprom.h":
Code:
 #ifndef _eeprom_h_
 #define _eeprom_h_

#include <pic18.h>
#include "Types.h"

#define EepromWrite8 eeprom_write //use hi-tech macro
#define EepromRead8 eeprom_read  //use hi-tech macro

void EepromWrite16(U8 address, U16 data)
U16 EepromRead16(U8 address)
void EepromWrite32(U8 address, U32 data)
U32 EepromRead32(U8 address)
void EepromWriteString(U8 address, U8* buffer, U8 len)
void EepromWriteFloat(U8 address, float data)
float EepromReadFloat(U8 address)
void EepromReadString(U8 address, U8* buffer, U8 len)

 
 #endif //_eeprom_h_

File "Eeprom.c":
Code:
#define _eeprom_c_
#include "Types.h"
#include "Eeprom.h"


void EepromWrite16(U8 address, U16 data)
{
static U8 i;

for(i = 0; i < 2; ++i)
{
EepromWrite8((U8)(address + i), *((U8 *)(&data) + i));
}
}

U16 EepromRead16(U8 address)
{
   static U8  i;
   static U16 near data;

   for(i = 0; i < 2; ++i)
   {
     *((U8 *)(&data) + i) = EepromRead8((U8)(address + i));
   }
   return(data);
}

void EepromWrite32(U8 address, U32 data)
{
static U8 i;

for(i = 0; i < 4; ++i)
{
EepromWrite8((U8)(address + i), *((U8 *)(&data) + i));
}
}

U32 EepromRead32(U8 address)
{
static U8  i;
U32 data;

for(i = 0; i < 4; ++i)
{
*((U8 *)(&data) + i) = EepromRead8((U8)(address + i));
}
return data;
}

void EepromWriteString(U8 address, U8* buffer, U8 len)
{
U8 i;
for(i = 0; i < len ; ++i)
{
EepromWrite8((U8)(address + i), *(buffer + i));
}
}

void EepromWriteFloat(U8 address, float data)
{
static U8 i;

for(i = 0; i < 4; ++i)
{
EepromWrite8((U8)(address + i), *((U8 *)(&data) + i));
}
}

float EepromReadFloat(U8 address)
{
static U8 i;
float data;

for(i = 0; i < 4; ++i)
{
*((U8 *)(&data) + i) = EepromRead8((U8)(address + i));
}
return data;
}

void EepromReadString(U8 address, U8* buffer, U8 len)
{
U8 i;
for(i = 0; i < len; ++i)
{
buffer[i] = EepromRead8((U8)(address + i));
}
}


To use this driver within a project, include "Eeprom.h" in the file you wanna use eeprom functions and build "Eeprom.c" along with other project files.
Logged

- Brain juice -
shobits1
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 15
-Receive: 10


« Reply #1 on: March 25, 2008, 01:10:20 01:10 »

Well in my case i preffer my code since it uses less space, and can be used with anysize of data (like struct), also it should be capable to read and write from flash memory only you must set EEPGD (i don't test it).

Code:
void Read_Eeprom(BYTE Address, PDATASTRUCT pData, BYTE cDataSize)
{
  BYTE  index;
  BYTE  *DataPtr = (BYTE *)pData;
 
  for( index=0; index < cDataSize; index++ )        //write all data bytes
  {
      while (WR)                                              //check for write in progress
          continue;
      EEADR       = Address+index;                     //the data address
      EEPGD       = 0;                                      //use eeprom to read data
      RD            = 1;                                      //start writing process
      DataPtr[0] = (BYTE)EEDATA;                    //data must be 8-bit, write byte per byte
      DataPtr++;                                            //set DataPtr to the next BYTE
   }
}

and this one for writting:
Code:
void Write_Eeprom(BYTE Address, PDATASTRUCT pData, BYTE cDataSize)
{
     BYTE  index;
     BYTE  *DataPtr = pData;
     if( GIE )
         CARRY=1;
     for( index=0; index < cDataSize; index++ )         //write all data bytes
     {
         while( WR )                                              //check for write in progress
            continue;
         EEADR   = Address+index;                          //the data address
         EEDATA = (BYTE)(DataPtr[0]);                   //data must be 8-bit, write byte per byte
         EEPGD   = 0;                                           //use eeprom to store data
         GIE       = 0;                                           //disable GIE if used
         WREN    = 1;                                          //enable write operation
         EECON2 = 0x55;                                      //special instrucion
         EECON2 = 0xAA;                                      //required to excute write program
         WR       = 1;                                           //start writing process
         WREN    = 0;                                           //disable write operation
         DataPtr++;
      }
      while (WR)                                                 //wait until write complete
         continue;

      if( CARRY )
         GIE=1;
}

best regards
Logged
jenya7
Newbie
*
Offline Offline

Posts: 11

Thank You
-Given: 26
-Receive: 16


« Reply #2 on: March 27, 2008, 10:49:46 10:49 »

it's a very good idea, i always wanted to learn Hi-Tech compiler!  Smiley
Logged
ZioFester
Junior Member
**
Offline Offline

Posts: 46

Thank You
-Given: 21
-Receive: 31


WWW
« Reply #3 on: April 18, 2008, 08:45:23 20:45 »

optimal idea! anke I would want to use this compiler, all say that it is optimal but until to hour MikroC and CCS, have given various troubles to me then prefer to use this. Writing these library creed that many more persons will want to use it. Some library them I and others are writing the stò finding on the forum. We could insert also those already introduced.

PIC IS BEAUTIFUL
Logged

cddx
Newbie
*
Offline Offline

Posts: 10

Thank You
-Given: 27
-Receive: 0


« Reply #4 on: April 23, 2008, 02:37:59 14:37 »

it's good! it makes code clear and readable, the way i like!
Logged
bliviudaniel
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 25
-Receive: 9


WWW
« Reply #5 on: July 14, 2008, 07:54:17 19:54 »

you can find some basic draviers for PIC16F877A ( but easy modifiable for other PIC16F) here:

http://liviu.budaciu.ro/minisumo/mr1/MainProgram3.zip

You cand find them in /bios folder.

Unfortunately, I didn't create any documentation for them. If someone may find them useful, he can use without any obligation or warranty Smiley
Logged

BLD
dfnr2
V.I.P
Newbie
*****
Offline Offline

Posts: 8

Thank You
-Given: 7
-Receive: 19


« Reply #6 on: July 10, 2011, 10:54:22 22:54 »

Hello,

When I switched from CCS to Hi-Tech C, I found the file at this link: http://www.eagleairaust.com.au/code/commdefs.pdf on the web, which contains a number of really useful #defines which provide CCS-like interfaces to various PIC peripherals.  I did update it a bit to work with the chip I was using and later a 16F7X part, and am now porting it along with my firmware to a 16f88x chip; the file in the PDF is a bit outdated, from 1999, but using the pic datasheets, it is easy to bring it up to date for newer chip families. 

The #include file approach works very well for the Hi-Tech compilers because there is no provision for inlining functions.  That means that every interface implemented as a function call takes up a valuable stack level on those mid-range PICs.  This approach is as convenient as a library; the code looks the same; unused interfaces take up no space; and the code is in-line.

Perhaps it would be worth starting with this file (I have versions that I know compile for certain PICS)--or start a similar new file from scratch--and instrument it to work with a broad range of PIC chips, but make it easily and flexibly configured for the various pic families with a #define system.

Dave
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC