Här kommer delar av koden:
Main.c
Kod: Markera allt
#include "C:\\Documents and Settings\\Tomas\\Mina dokument\\Projekt\\Pulslogger\\Code\\Pulslogger_Auto.h"
// **********
//
// Application Designer Variables
//
// **********
//
// This file is automatically generated. Any changes will be overwritten when
// the application is regenerated
//
void LoadOscCal();
// Conditional Defines
const int LCDPORT=&LCDData0Port; // LCD Module Driver
const int LCDEPORT=&LCDEPort;
const int LCDRSPORT=&LCDRSPort;
const int LCDRWPORT=&LCDRWPort;
const int LCDEBIT=LCDEBit;
const int LCDRSBIT=LCDRSBit;
const int LCDRWBIT=LCDRWBit;
void ADLCDInit();
 // Port Input
 // Port Input
 // Port Input
 // Port Input
#define SERINTdivH APROCFREQ/16/SERINTRATE-1 // Serial Interface using USART hardware
#define SERINTdiv APROCFREQ/64/SERINTRATE-1
#if SERINTdivH>255
 #define NoBRGH 1
#endif
#define TXSTA0 TXSTA
#define SPBRG0 SPBRG
#define RCSTA0 RCSTA
#define RC1IF RCIF
//
// Main function
//
void main()
{
 #if HASOSCCAL==1
  LoadOscCal();
 #endif
 
 // Initialisation Code
 #ifdef NoBRGH
  TXSTA=(1<<TXEN);
  SPBRG=SERINTdiv;
 #else
  TXSTA=(1<<BRGH)|(1<<TXEN);
  SPBRG=SERINTdivH;
 #endif
 RCSTA=(1<<SPEN)|(1<<CREN);
 
 // End Initialisation Code
 PORTC|=0xff;
 PORTD|=0xff;
 TRISD&=0xf1;
 TRISC&=0xbf;
 ADLCDInit();
 
 UserInitialise();
 
 // Finally enable interrupts
  
 INTCON|=(1<<GIE);
 
 // Main Loop
 
 while(1)				
 {					// Loop forever
  UserLoop();
  #ifdef WatchDogUsed			
   #pragma asmline clrwdt		; Clear watchdog timer if used
  #endif
 }
}
//
// Interrupts
//
const int QuickInt=1;
void Interrupt()
{
 // Priority Interrupts first
 // Other Interrupts
 #pragma asmline goto UserInterrupt	; PIC Assembler - goto user interrupt
 #pragma asmline UserIntReturn::	; Return to here after user routine
}
//
// Load oscillator calibration value on reset for 14 bit processors
//
#if HASOSCCAL==1
	#pragma asm
		module "LoadOscCal"
		
		; 
		; Oscillator tuning is not relevant for 18 series at present
		;
		; This is left here for future use
LoadOscCal::
                MRET 0
                
                endmodule                
	#pragma asmend
#endif
Kod: Markera allt
#include "C:\\Documents and Settings\\Tomas\\Mina dokument\\Projekt\\Pulslogger\\Code\\Pulslogger_Auto.h"
#include "Pulslogger_defs.h"
#include "Pulslogger_sci.h"
#include "Pulslogger_Timer0.h"
#include "Pulslogger_i2str.h"
// context save on interrupt
unsigned char tmp_wreg;
unsigned char tmp_status;
unsigned char tmp_bsr;
unsigned char tmp_0;
unsigned char tmp_1;
unsigned char tmp_2;
unsigned char tmp_3;
unsigned char tmp_fsr2l;
unsigned char tmp_fsr2h;
unsigned char uc_ch;
unsigned int pkg_cnt;
//----------------------------
char str[22];
unsigned int cnt0_ui;
unsigned int cnt1_ui;
unsigned int cnt2_ui;
unsigned int cnt3_ui;
bituchar incnt_bc;
unsigned char in1_uc;
unsigned char in2_uc;
unsigned char invar1_uc;
unsigned char invar2_uc;
unsigned char s1_uc;
unsigned char s2_uc;
unsigned char s3_uc;
unsigned char sx_sh;
//----------------------------
/*
	2  STX  Start of text
	3  ETX  End of text
	17 XON  Transmission on
	19 XOFF Transmission off
*/
// ROM constants
const char startstr[]= {
	17, 10, 13, 'P', 'a', 'c', 'k','e', 't',' ',  0
};
const char spacestr[]={' ', ',', ' ', 0};
const char endstr[]= {',', ' ', 'E', 'n', 'd', 19 ,0};
//----------------------------
//
// This file includes all user definable routines. It may be changed at will as
// it will not be regenerated once the application has been generated for the
// first time.
//
//*******************************************************************************
//
// Insert your interrupt handling code if required here. 
// Note quick interrupts are used so code must be simple
// See the manual for details of quick interrupts.
//
void UserInterrupt()
{
		// save important registers
	#asmline MOVWF  tmp_wreg
	tmp_status = STATUS;
	tmp_bsr = BSR;
	#asmline MOVFF 0, tmp_0;
	#asmline MOVFF 1, tmp_1;
	#asmline MOVFF 2, tmp_2;
	#asmline MOVFF 3, tmp_3;
	tmp_fsr2l = FSR2L;
	tmp_fsr2h = FSR2H;
	// Insert your code here
	
	if ( bTMR0IF ) {
		TMR0H = TIMER0_COUNTER_HIGH;
		TMR0L = TIMER0_COUNTER_LOW;
		
		in1_uc = PORTC & 0b00001111;
		
		s1_uc = in1_uc ^ in2_uc;
		s2_uc = s1_uc & invar1_uc;
		s3_uc = (~s1_uc) & in1_uc;		
		invar1_uc = s2_uc | s3_uc;
		
		incnt_bc.data = invar1_uc & (~invar2_uc);
		
		if(incnt_bc.b0) {
			cnt0_ui++;
			uc_ch=1;
		}
		if(incnt_bc.b1) {
			cnt1_ui++;
			uc_ch=1;
		}
		if(incnt_bc.b2) {
			cnt2_ui++;
			uc_ch=1;
		}
		if(incnt_bc.b3) {
			cnt3_ui++;
			uc_ch=1;
		}
		
		invar2_uc = invar1_uc;
		in2_uc    = in1_uc;
		
		TIMER0_bTMR0IF = 0;
	}
	
	// restore important registers
	#asmline MOVFF tmp_0, 0;
	#asmline MOVFF tmp_1, 1;
	#asmline MOVFF tmp_2, 2;
	#asmline MOVFF tmp_3, 3;
	FSR2L = tmp_fsr2l;
	FSR2H = tmp_fsr2h;
	BSR = tmp_bsr;
	#asmline MOVF tmp_wreg, W
	STATUS = tmp_status;
	
  #asmline goto UserIntReturn	; PIC Assembler - go back to interrupt routine
}
//*******************************************************************************
//
// Insert your initialisation code if required here. 
// Note that when this routine is called Interrupts will not be enabled - the 
// Application Designer will enable them before the main loop
//
void UserInitialise()
{
	cnt0_ui = 0;
	cnt1_ui = 0;
	cnt2_ui = 0;
	cnt3_ui = 0;
	pkg_cnt = 0:
	uc_ch = 0;
	
	incnt_bc.data   = 0;
	in1_uc    = 0;
	in2_uc    = 0;
	invar1_uc = 0;
	invar2_uc = 0;
	
	Timer0_init();
	LCDClear();
	LCDPrintAt(0,0);
	LCDString("DBC-System AB");
	LCDPrintAt(0,1);
	LCDString("EventLogger ver 1.0");
	LCDPrintAt(20,0);
	LCDString("Copyright 2008");
	LCDPrintAt(20,1);
	LCDString("Initializing");
	Wait(2000);
	LCDClear();
	LCDPrintAt(0,1);
	LCDString("System Rdy, Running");
	Wait(2000);
	LCDClear();
}
//*******************************************************************************
//
// Insert your main loop code if required here. This routine will be called
// as part of the main loop code
//
void UserLoop()
{
	if (uc_ch==1)
	{
	pkg_cnt++;
	Sci_puts_rom( startstr );
	u2str( str, pkg_cnt, I2STR_NODOT	); 
	Sci_puts( str );
	Sci_put ( ';' );
	Sci_puts_rom ( spacestr ); 
	u2str( str, cnt0_ui, I2STR_NODOT	);
	Sci_puts( str );  
	Sci_puts_rom ( spacestr );
	LCDPrintAt(0,0);
	LCDString("Ch 0= ");
	LCDString(str);
	LCDString(" Wh ");
	u2str( str, cnt1_ui, I2STR_NODOT	);
	Sci_puts( str );  
	Sci_puts_rom ( spacestr );
	LCDPrintAt(0,1);
	LCDString("Ch 1= ");
	LCDString(str);
	LCDString(" Wh ");
	u2str( str, cnt2_ui, I2STR_NODOT	);
	Sci_puts( str );  
	Sci_puts_rom ( spacestr );
	LCDPrintAt(20,0);
	LCDString("Ch 2= ");
	LCDString(str);
	LCDString(" l/m ");
	u2str( str, cnt3_ui, I2STR_NODOT	);
	Sci_puts( str );  
	Sci_puts_rom( endstr );
	LCDPrintAt(20,1);
	LCDString("Ch 3= ");
	LCDString(str);
	LCDString(" l/m ");
	
	}
	uc_ch=0;
	
}
//
// User occurrence code
//
Kod: Markera allt
#include "Pulslogger_defs.h"
#include "Pulslogger_sci.h"
//----- functions ----------------------------------------
void 	Sci_init(void) {
// 4800		103
//	TXSTA  = 0b00000010 ;
//	BAUDCON= 0b01000000 ;
//	RCSTA  = 0b00000000 ;
//	OpenUSART( 	USART_TX_INT_OFF  &	USART_RX_INT_OFF  &
//             	USART_ASYNCH_MODE & 	USART_EIGHT_BIT   &
//             	USART_CONT_RX     & 	USART_BRGH_LOW, 	103 );
}
//--------------------------------------------------------
void	Sci_put(unsigned char	c) {
  	while(!SCI_bTRMT );
	SCI_TXREG = c;
}
//--------------------------------------------------------
void	Sci_puts( char	*s) {
	while( *s )	{ 
    	while(!SCI_bTRMT );
    	SCI_TXREG = *(s++);
 	} 
}
//--------------------------------------------------------
void	Sci_puts_rom( const char *s) {
	while( *s )	{ 
    	while(!SCI_bTRMT );
    	SCI_TXREG = *(s++);
 	} 
}
//--------------------------------------------------------
unsigned char	Sci_get_wait(void) {
	while(!SCI_bRCIF);	
	return SCI_RCREG;    
}
//--------------------------------------------------------
unsigned char	Sci_gets_wait( char *s, unsigned char len) {
	unsigned char c;
	unsigned char cnt = 0;	
	
	// empty FIFO
	c = SCI_RCREG;
	c = SCI_RCREG;
	
	if( SCI_bOERR ) {
		SCI_bCREN=0;
		SCI_bCREN=1;
	}
	
				
	while(len--) {
		while(!SCI_bRCIF);	
		
		c = SCI_RCREG;    
		if ( c == '\r' || c == '\n' || c == 0 ) {
			return cnt;	  
		}      
		*(s++) = c;    		
		cnt++;
	}
	
	return cnt;	
}
//--------------------------------------------------------
Kod: Markera allt
// ***************************************************************
// *               Copyright (C) Frank Linder                    *
// * Permission is granted to use, modify, or redistribute this  *
// * software so long as it is not sold or exploited for profit. *
// *    Provided "as is" without express or implied warranty.    *
// ***************************************************************
#include "Pulslogger_i2str.h"
void i2str(unsigned char *str, int n, unsigned char dot){
	if(n<0) {
		n=-n;
		u2str( str+1, (unsigned int)n, dot);
		str[0]='-';		
		return;
	}
	
 	u2str( str, (unsigned int)n, dot);
}
//--------------------------------------------------------
void u2str(unsigned char *str, unsigned int n, unsigned char dot){
	unsigned char r;
	unsigned char i;
		
	str[6]=0;
	
	i=5;
	while	(i<10u){
		r=n%10;
		n/=10;
		if(dot==i) {
			str[i]='.';
			i--;
		}
		if(n==0u && dot>i) {
			str[0]=r+48;	
			r=1;
			while(i<6u) {
				i++;
				str[r]=str[i];
				r++;
			}
			return;
		}
		
		str[i]=r+48;
		i--;
	}	
}
//--------------------------------------------------------
Kod: Markera allt
#include "Pulslogger_defs.h"          
#include "Pulslogger_timer0.h"          
//-------------------------------------------------------------------
// defines                                   
//------------------------------------------------------------------- 
#if (TIMER0_PRESCALE_VALUE == 2)
#define TIMER0_PRESCALE  (0)
#elif ( TIMER0_PRESCALE_VALUE == 4 )
#define TIMER0_PRESCALE  (1)
#elif ( TIMER0_PRESCALE_VALUE == 8 )
#define TIMER0_PRESCALE  (2)
#elif ( TIMER0_PRESCALE_VALUE == 16 )
#define TIMER0_PRESCALE  (3)
#elif ( TIMER0_PRESCALE_VALUE == 32 )
#define TIMER0_PRESCALE  (4)
#elif ( TIMER0_PRESCALE_VALUE == 64 )
#define TIMER0_PRESCALE  (5)
#elif ( TIMER0_PRESCALE_VALUE == 128 )
#define TIMER0_PRESCALE  (6)
#elif ( TIMER0_PRESCALE_VALUE == 256 )
#define TIMER0_PRESCALE  (7)
#else
#error Invalid TICK_PRESCALE_VALUE specified.
#endif
//-------------------------------------------------------------------
// variables                    
//-------------------------------------------------------------------
unsigned int  timer0_cnt_ui;
unsigned int  timer0_sec_ui;
//-------------------------------------------------------------------
// functions                    
//-------------------------------------------------------------------
void Timer0_init(void) { 
	timer0_cnt_ui = 0;
	timer0_sec_ui = 100;
	
    // Initiate the timer.
    TMR0L = TIMER0_COUNTER_LOW;
    TMR0H = TIMER0_COUNTER_HIGH;
    // Set prescaler
    T0CON = 0x00 | TIMER0_PRESCALE;
    // Start the timer.
    TIMER0_bTMR0ON = 1;            
    
#ifdef TIMER0_INTERRUPT
    TIMER0_bTMR0IF = 1;
    TIMER0_bTMR0IE = 1;
#endif
}
//-------------------------------------------------------------------
/*
void Timer0_update(void) {
	if ( bTMR0IF ) {
		TMR0H = TIMER0_COUNTER_HIGH;
		TMR0L = TIMER0_COUNTER_LOW;
		timer0_cnt_ui++;
		
		timer0_sec_ui--;
		if( timer0_sec_ui ==0 ) {
			timer0_sec_ui = 100;
			#asmline btg PORTD, 7	
		}	
		if( !PANIK ) {
			glcd_clear_all();
			glcd_xy(2,3);
			glcd_puts_rom( paniken );
			glcd_puts_rom( paniken );
			glcd_puts_rom( paniken );
			Wait(2000); // delay in ms	
		}
					
		
		TIMER0_bTMR0IF = 0;
	}
}
//-------------------------------------------------------------------
*/
Kod: Markera allt
#include "C:\\Documents and Settings\\Tomas\\Mina dokument\\Projekt\\Pulslogger\\Code\\Pulslogger_Auto.h"
// *** Input File - C:\Program\FED\PIXIE\APPWIZ\APPWIZ18\misc.c
#ifdef LCDUsed	 	// Init Code for LCD
void ADLCDInit()
{
 LCD(-LCDnLines);
}
#endif
Kod: Markera allt
#include <P18F452.h>
#include <P18F452_bits.h>
#include <PortBits.h>
#include <delays.h>
#include <displays.h>
#define APROCFREQ 40000000
#define BITSIZE 16
#define BOOTADDRESS 0
#define FIRSTRAM 0x00
#define LASTRAM 0x5FF
#define HASOSCCAL 0
#define nPAGESRAM 1
#define nPAGESROM 1
//
// Header file - should be included in all C files used within the program
// This file is created automatically and should not be changed
//
//
// Functions
//
void UserInitialise();			// Your initialisation code
void UserInterrupt();			// Your interrupt code
void UserLoop();			// your Main loop code
#define PortInnCopy 4
// **********
//
// Wait for W milli-seconds
//
// **********
#define WaitWmUsed 1
// **********
//
// LCD Module Driver
//
// **********
#define LCDUsed 1
#define LCDnLines 4
#define LCDData0Port PORTD
#define LCDData0Bit 4
#define LCDData1Port PORTD
#define LCDData1Bit 5
#define LCDData2Port PORTD
#define LCDData2Bit 6
#define LCDData3Port PORTD
#define LCDData3Bit 7
#define LCDRSPort PORTD
#define LCDRSBit 3
#define LCDRWPort PORTD
#define LCDRWBit 2
#define LCDEPort PORTD
#define LCDEBit 1
// **********
//
// Port Input
//
// **********
#define PortInUsed 1
#define PortIn3Used 1
#define In3Port PORTC
#define In3Bit 3
// **********
//
// Port Input
//
// **********
#define PortIn2Used 1
#define In2Port PORTC
#define In2Bit 2
// **********
//
// Port Input
//
// **********
#define PortIn1Used 1
#define In1Port PORTC
#define In1Bit 1
// **********
//
// Port Input
//
// **********
#define PortIn0Used 1
#define In0Port PORTC
#define In0Bit 0
// **********
//
// Serial Interface using USART hardware
//
// **********
#define USARTUsed 1
#pragma asmline _USARTUsed=1
#define SERINTRATE 19200
#pragma asmline _SERINTRATE=19200
#define RxPort PORTC
#define RxBit 7
#pragma asmline _RxPort=PORTC
#pragma asmline _RxBit=7
#define TxPort PORTC
#define TxBit 6
#pragma asmline _TxPort=PORTC
#pragma asmline _TxBit=6
// **********
//
// In Circuit Debugger Element
//
// **********
#define ICDUsed 1
#pragma asmline _ICDUsed=1
#define EnableICD 1
#pragma asmline _EnableICD=1
#define BitRate 19200
#pragma asmline _BitRate=19200
#define DebuggerPort PORTD
#define DebuggerBit 0
#pragma asmline _DebuggerPort=PORTD
#pragma asmline _DebuggerBit=0
// **********
//
// Application Designer Variables
//
// **********
// Defines specified by 1 or more elements
Kod: Markera allt
// main.h
// ***************************************************************
// *               Copyright (C) Frank Linder                    *
// * Permission is granted to use, modify, or redistribute this  *
// * software so long as it is not sold or exploited for profit. *
// *    Provided "as is" without express or implied warranty.    *
// ***************************************************************
#ifndef defs_h
#define defs_h
#include "Pulslogger_Auto.h"
typedef union{
	unsigned char data;
	struct {
		unsigned b0:1;
		unsigned b1:1;
		unsigned b2:1;
		unsigned b3:1;
		unsigned b4:1;
		unsigned b5:1;
		unsigned b6:1;
		unsigned b7:1;
	} ;
} bituchar;
typedef union {
	unsigned int iu;
	int is;
	struct{
		unsigned char lu;
		unsigned char hu;	
	};
	struct{
		char ls;
		char hs;	
	};
} word; 
typedef union {
	unsigned long longu;
	long longs;
	struct{
		int ls;
		int hs;	
	};
	struct{
		unsigned int lu;
		unsigned int hu;	
	};
} dword; 
#endif
Kod: Markera allt
#ifndef sci_h
#define sci_h
//----- defines ------------------------------------------
#define SCI_bTRMT	bTRMT
#define SCI_bRCIF	bRCIF
#define SCI_bOERR	bOERR
#define SCI_bCREN	bCREN
#define SCI_RCREG	RCREG
#define SCI_TXREG	TXREG
//----- functions ----------------------------------------
void 				Sci_init(void);
void				Sci_put(unsigned char);
void				Sci_puts( char *s) ;
void				Sci_puts_rom( const char *s) ;
unsigned char	Sci_get_wait(void);
unsigned char	Sci_gets_wait( char *s, unsigned char len);
 
//--------------------------------------------------------
#endif
// fosc=32MHz		high speed  FOSC / (16 * (spbrg + 1))
//						low  speed  FOSC / (64 * (spbrg + 1))
//-----------------------------------------------------
// low speed  500k / (spbrg + 1))
// baud		baud rate register (spbrg)	
//	1200		
// 2400		206
// 4800		103
// 9600		
// high speed  2M / (spbrg + 1))
// baud		baud rate register (spbrg)	
// 4800		
// 9600		206
// 19200		103
// 38400		51
// 57600		33
// 115200	16
Kod: Markera allt
#ifndef TIMER0_H
#define TIMER0_H
       
// defines                                   
#define TIMER0_bTMR0ON bTMR0ON
#define TIMER0_bTMR0IF bTMR0IF
#define TIMER0_bTMR0IE bTMR0IE
#define TIMER0_INTERRUPT
#define TIMER0_PRESCALE_VALUE   4
#define TIMER0_TICKS_PER_SECOND 10000
#define TIMER0_TEMP_VALUE_1  ((APROCFREQ / 4) / (TIMER0_TICKS_PER_SECOND * TIMER0_PRESCALE_VALUE))
#define TIMER0_TEMP_VALUE    (65535 - TIMER0_TEMP_VALUE_1)
#define TIMER0_COUNTER_HIGH  ((TIMER0_TEMP_VALUE >> 8) & 0xff)
#define TIMER0_COUNTER_LOW   (TIMER0_TEMP_VALUE & 0xff)
                                   
// extern variables
// extern functions
void Timer0_init(void);
void Timer0_update(void);
#endif
Kod: Markera allt
#ifndef i2str_h
#define i2str_h
#define I2STR_NODOT	20
#define I2STR_1DEC	4
#define I2STR_2DEC	3
#define I2STR_3DEC	2
#define I2STR_4DEC	1
void i2str(unsigned char *str,          int n, unsigned char dot);
void u2str(unsigned char *str, unsigned int n, unsigned char dot);
#endif
Följande filer är unika för IDE'n
main.c
auto.h
lib.h
Genom ide'ns uppbyggnad, hamnar funktionen "void main(void){}"  i main.c
Användarlkoden körs som anrop från main.c, samma gäller interupten, som också hanteras i main.c.
För att det hela skall fungera behövs diverse bibliotek såsom bl.a. lcd-rutioner mm.
Detta följer med miljön från FED.
det finns naturligtvis en uppsjö av drivisar till LCD-displayer.
Bl.a. har Baronen (Baron3d) här på forumet en del på sin
sida.