Welcome To The Family : C6808 Code Development System For Freescale™ RS08
Welcome To The Family : C6808 Code Development System For Freescale™ RS08
Welcome To The Family : C6808 Code Development System For Freescale™ RS08
02A4 A ox40;
02A6 B gs&0x20)
02A9 C table();
to the family…
Memory Management
C6808 includes enhanced memory management such as named memory directives.
Local address space directives allows the user to maximize the use of RAM, direct the
placement of local variables, re-use RAM locations and pass multiple arguments to
functions. Other named memory directives add support for variables, allocated externally
or internally, that are managed through software drivers.
Features in Detail
• Highly-optimized generated code. Full versions
generate ROMable code; demonstration versions
generate listing files with assembly.
02A4 A ox40;
02A6 B gs&0x20) • Ports and other resources are declared and protected
02A9 C table(); using #pragma directives.
• Named address spaces support the grouping of
Byte Craft Limited variables at specific memory locations.
A2-490 Dutton Drive
• C data types include register-oriented types for
Waterloo, Ontario
direct access to processor registers when necessary.
Canada – N2L 6H7
+1 519.888.6911 • Data structures of arbitrary complexity, including
[email protected] packed bit fields in structures.
2 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
Data Types
Our research has told us that choosing the right data types for the application is key to a
successful embedded project. C offers numerous specialized data types, and the coding
environment in which to use them. The only limit is the hardware resources of your
chosen part.
Type Sizes: C6808 offers signed and unsigned integer types in 8,
Lucky
16, 24, and 32 bits. Choose data types to suit the solution of your
problem, and let the compiler worry about the carry bit. Numbers
Fixed point: C6808 supports TR 18037 fixed point and How will your math
calculations change
accumulator types. _Fract types represent fractional values due to the instruction
between 0 and 1, and _Accum types have small integer set differences in
components. RS08?
Type Bits C6808 uses
optimization
unsigned short _Fract 8
strategies like
unsigned _Fract 16 shifted number
unsigned long _Fract 24 systems to
implement various
signed short _Fract s.7
data types and
signed _Fract s.15 operations in RS08.
signed long _Fract s.23 We worry about
unsigned short _Accum 8.8 math problems so
unsigned _Accum 8.16
you can focus on
your solutions.
unsigned long _Accum 8.24
Fixed point math is implemented by an external library, with accompanying source code.
Unambiguous sizes: C6808 offers ISO types that make it clear what values can be
expected.
uint8_t uint16_t uint24_t uint32_t
DRAFT DOCUMENTATION 3
Byte Craft Limited DRAFT DOCUMENTATION
_Bool: C6808 supports _Bool, using bit test and set instructions wherever possible. The
deprecated Byte Craft Limited bit type is still supported.
bits: Code Development Systems have always offered the bits type, a structure of eight
bits that are individually addressable (with constant members).
Named Memory
Where the problem space forces you to dwell on addressing modes, the solution space
offers named memory spaces to organize your variable allocations. This separates low-
level details about variable access from the high-level design of the program.
Header file declarations, both standard and user-supplied, organize memory into named
sections. They can represent scratchpad RAM versus persistent data, or read-only
resources separate from the program and its constant objects. They can even be used to
issue warnings when one class of objects exceeds memory budgets, though others do not.
Named memory can be more than just storage. C6808 offers user-implemented memory
declarations: accesses to variables declared in these areas are implemented using device
driver routines. In the past, this type of memory has been used for serial bus
communications, Flash programming, and other driver-oriented applications.
Here’s an example of accessing variables declared on an external SPI EEPROM device:
1000 0100 #pragma memory RAM _Access bySPI [0x100] @ 0x1000,
ReadSPI, WriteSPI;
void SELECT_SPI_EEPROM(void);
void DESELECT_SPI_EEPROM(void);
void WRITE_SPI_ADDR(unsigned int addr);
void WRITE_SPI_DATA(char in);
char READ_SPI_DATA(void);
4 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
void main(void)
{
381B B6 00 LDA $00 count = persist_count;
381D AD E1 BSR $3800
381F B7 20 STA $20
/* process */
Combining the user’s logical divisions of memory with the different types of physical
memory is exactly the type of work most successfully accomplished by an optimizing
compiler.
Hardware Access
For those times when hardware access is unavoidable, C6808 brings these details into the
C language and into the solution space. There is nothing you can do in assembly that
can’t be done in C.
Register access: Following on from named memory, C6808 offers direct access to
processor registers for specialized purposes. Reading and writing variables of (storage
class) type register _A and register _CCR generates stores and loads as appropriate.
This applies even to registers that can’t be directly accessed through the instruction set,
another benefit of C.
Device-specific instructions: These are brought out as C intrinsics:
WAIT(); NOP(); SEC(); BKGD(); ROLA();
STOP(); CLC();
Reset code: The state of the processor is generated automatically. Variables are
initialized, and a user-defined __STARTUP() routine is executed if defined. __STARTUP()
can serve as a debugging-specific shim, compiled in for testing and then simply left out
for production.
•••
DRAFT DOCUMENTATION 5
Byte Craft Limited DRAFT DOCUMENTATION
6 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
Insider Knowledge
Our experience tells us that hand-written assembly can reach a 16-to-1 ratio of
program code to RAM. For every new RAM variable, typically 16 bytes of
program store are needed. Compilers’ superior memory accounting can
generally equal or beat the best handwritten assembly ROM to RAM ratios.
The MC9RS08KA2 has a ROM to RAM ratio of 32. With 32 bytes ROM for
every byte of RAM, applications on this processor will benefit from every
optimization possible to fit their data into the RAM available.
DRAFT DOCUMENTATION 7
Byte Craft Limited DRAFT DOCUMENTATION
Event-driven Programming
Traditional interrupts divert the processor’s attention to an asynchronous task, and restore
it after the interrupt service is complete. HC08 and HCS08 followed on in the HC05
practice of pushing the entire processor status on the stack during interrupt servicing. The
biggest cost of this is the amount of time and resources needed to support this operation.
But is it really necessary?
We’ve dealt with a variety of architectures, some of which are run-to-completion—no
asynchronous events disturb the processor between logical tasks. Experience has shown
us that run-to-completion, while risking delays in response, helps eliminate:
• Expensive preservation of processor state during context switches.
• Complexity in managing local variable values.
• Complexity in interrupting and restarting main line software.
Event-driven programming, where execution takes place only in response to external
stimuli and is usually run-to-completion, is a viable alternative.
void main(void)
{
while(1)
{
WAIT();
if (KBISC.KBF)
{
8 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
Threads
Interrupts on RS08 do not actually interrupt the flow of execution. They may wake the
processor from a WAIT() or STOP() mode, but they can only be handled when software
invokes a specific thread of execution.
Byte Craft Limited has designed a threaded programming model that makes event-driven
programming in C easy and intuitive. We use the compiler to organize sets of event and
state tests in one coherent architecture.
To get the definitions right: a thread is a C function with the added semantics of
centralized conditional dispatch. The elements of C6808 thread programming are as
follows:
• Thread declarations appear as #pragma directives. Each thread has its own gating
expression that evaluates to a Boolean value. The expression can test interrupt
source flags, global variables, or I/O ports.
#pragma thread identifier keyword (expression);
DRAFT DOCUMENTATION 9
Byte Craft Limited DRAFT DOCUMENTATION
Evaluation
All thread expressions are evaluated within __DISPATCH() in declaration order (or during
the equivalent phase of RESET). When any expression is completely evaluated, and
evaluates to true, that thread is run immediately. If no expressions are true, execution
falls through to the next main line program instruction after the call to __DISPATCH().
Examples
Real Time Interrupt
Implementing a real time interrupt for a real-time kernel is a matter of choosing the right
expressions for #pragma thread directives:
unsigned int count = 0;
void __TIM(void)
{
count++;
}
10 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
void __TIMRESET(void)
{
count = 0;
SRTISC.RTIACK = 1;
}
void main(void)
{
while(1)
__DISPATCH();
}
Two sources
This example is comparable to the RS08-specific design described at the beginning of the
article.
#pragma thread KBI wait (KBISC.KBF == 1);
/* interrupt functions */
void KBI(void)
{
// actions
KBISC.KBACK = 1;
}
void MTIM(void)
{
// actions
MTIMSC.TRST = 1;
}
void main(void)
{
while(1) __DISPATCH();
}
In this example, only the KBI and MTIM routines will be run, and only after a WAIT().
Future Directions
Threads and Libraries
One novel use of threads is to distribute interrupt service across several libraries. Each
library that requires event servicing can declare its own #pragma thread condition,
complete with macros as expression terms. The compiler will integrate the expressions
and thread calls during final compilation.
DRAFT DOCUMENTATION 11
Byte Craft Limited DRAFT DOCUMENTATION
12 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
if ((state == 0b1101) ||
(state == 0b1011) ||
3812 A1 0D CMP #$0D (state == 0b0010) ||
3814 37 0C BEQ $3822
3816 A1 0B CMP #$0B (state == 0b0100)) tally++;
3818 37 08 BEQ $3822
381A A1 02 CMP #$02
381C 37 04 BEQ $3822
381E A1 04 CMP #$04
3820 36 08 BNE $382A
3822 3C 21 INC $21
3824 36 02 BNE $3828
3826 3C 20 INC $20
3828 30 19 BRA $3843 else if ((state == 0b1110) ||
(state == 0b1000) ||
382A A1 0E CMP #$0E (state == 0b0001) ||
382C 37 0C BEQ $383A
382E A1 08 CMP #$08 (state == 0b0111)) tally--;
3830 37 08 BEQ $383A
3832 A1 01 CMP #$01
3834 37 04 BEQ $383A
3836 A1 07 CMP #$07
3838 36 09 BNE $3843
383A 4E 21 21 TST $21
383D 36 02 BNE $3841
DRAFT DOCUMENTATION 13
Byte Craft Limited DRAFT DOCUMENTATION
14 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
Theory
This method of A/D conversion is ratiometric. Software keeps two counts: the number of
positive comparator readings and the total number of readings taken. The ratio between
the two indicates the input voltage. The faster the A/D task can take place, the more
accurate the readings.
The circuit strives to keep the input voltage close to the switching voltage of the
comparator. The comparator is a flexible device that can operate independently of the
RS08. Though it can interrupt the RS08 on a change in its output, this design simply polls
it. It functions as an op-amp that the processor can watch.
The comparator’s positive input is set to the bandgap reference voltage source (1.218V).
Its negative input is tied to the input voltage through a current source resistor. A small
capacitor integrates the error current.
The digital output of the comparator is fed back into the input through another current
source. Because the voltage input is fed in through the negating input, the output of the
comparator is opposite to the difference between the bandgap input and the voltage under
test. This will cause the comparator output to oscillate. In a software-only implementation,
the same effect is created by constantly inverting an output pin with respect to the input.
The modulo timer task can take place along with other frequent modulo timer tasks. So
long as the comparator is sampled at regular intervals, this conversion is not time-
constrained.
Design
This is a schematic for the design using the 6-pin RS08KA2 part:
DRAFT DOCUMENTATION 15
Byte Craft Limited DRAFT DOCUMENTATION
Software
The required software appears at the end of the document. Some excerpts follow.
Using the RS08’s modulo timer, the conversion can take place as an interrupt task,
allowing the processor to perform other (interrupt-driven) tasks at the same time.
Configuration
The comparator is configured to run freely, and the modulo timer is set to generate an
interrupt.
/* configure the comparator */
ACMPSC = 1<<ACME //enable
|1<<ACBGS //bandgap select
|1<<ACF //clear flag
|0<<ACIE //do not enable interrupt
|1<<ACOPE //pass output to pin
380C 3E C7 13 MOV #$C7,$13 |0b11<<ACMOD //rising or falling edge.
380F ;
000C #define comparator_hi() (ACMPSC.ACF)
16 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
Event loop
This excerpt shows the while(1) statement that bounds the operating loop and the WAIT()
that heads it. We used WAIT() to allow the modulo timer to continue running. Whenever
the modulo clock rolls over, the program increments the total and (if needed) positive
counts.
while(1)
{
if(comparator_hi())
{
positivecount++;
At the end of the timer interrupt, the interrupt flag is reset and the loop is continued.
Calibration
The circuit can give an output in engineering units once calibrated. The sample software
incorporates calibration, but here are the steps:
1. Apply the maximum known reference voltage to the input.
2. Signal the software to count samples until the count of positive samples is an
engineering unit (i.e., 100, 1000, etc.)
3. Software records the count of total samples needed to reach the proper maximum
positive count, and returns to normal operation.
4. Apply a voltage to measure to the input.
5. Software performs a count of total samples matching the recorded value.
6. Use the resulting count of positive samples as an engineering value between zero
and the calibration maximum count of positive samples.
If you’re tempted to use a low-cost RS08 part in your design, but need full A/D
conversion, designing in a software-assisted A/D converter may serve your purposes.
Look at the complete source and generated listing files below:
A/D Converter Source Code
A/D Converter Listing File
DRAFT DOCUMENTATION 17
Byte Craft Limited DRAFT DOCUMENTATION
18 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
These declarations give us the makings of fuzzy logic rules. These rules test the 'truth' or
'falsehood' of the linguistic variable, and specify consequences accordingly.
/* Rules to follow */
FUZZY climateControl
{
IF room IS cold THEN ac IS OFF
IF room IS normal THEN ac IS OFF
IF room IS hot THEN ac IS ON
}
Fuzzy logic starts with crisp values, analyzes them according to membership functions,
and then uses consequence functions to arrive at a crisp result. There's nothing
indeterminate about fuzzy logic: given the same input, you get the same output every
time. The difference is in the ease of coding the algorithm.
DRAFT DOCUMENTATION 19
Byte Craft Limited DRAFT DOCUMENTATION
int main(void)
{
while(1)
{
/* find the temperature */
room = thermostat;
/* apply the rules */
climateControl();
/* switch the A.C. */
airCon = ac;
wait(10);
}
}
Using Fuzz-C fuzzy logic in a program is easy. The LINGUISTIC variables (and
CONSEQUENCE blocks alike) become variables in your program. Fuzzy logic rules
become a function that you call when needed to perform the fuzzy calculation.
Fuzz-C is a flexible system that allows all (scalar) data types supported by your C
compiler. It includes standard defuzzification methods, and accepts user-defined ones.
20 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* proportional error */
LINGUISTIC Error TYPE int MIN -90 MAX 90
{
MEMBER LNegative { -90, -90, -20, 0 }
MEMBER normal { -20, 0, 20 }
MEMBER close { -3, 0, 3 }
MEMBER LPositive { 0, 20, 90, 90 }
}
FUZZY pid
{
/* large moves for large proportional errors */
IF Error IS LNegative THEN ManVar IS LPositive
IF Error IS LPositive THEN ManVar IS LNegative
DRAFT DOCUMENTATION 21
Byte Craft Limited DRAFT DOCUMENTATION
22 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
of Compilers
strategies for different embedded platforms. We
are experts in dealing with processor architectures
designed for computer-generated code. Byte Craft
compiler code generation technology produces
tight, fast code. Byte Craft's tools equal or improve on the code density and execution
speed of well-written hand-coded assembler.
Byte Craft Limited works with our silicon partners to
develop benchmarks, leading to design wins and silicon
sales. Many sales initiatives start with benchmark tests.
Get Byte Craft Limited involved in this process; we
consistently win benchmarks, and we can demonstrate
through this process that we work with our silicon and 02A4 A ox40;
hardware partners in the best interest of our common 02A6 B gs&0x20)
customers. 02A9 C table();
Byte Craft Limited can provide marketing materials,
demos, and product information. Our demonstration
products generate listing files, with which users can see the
code we generate. We can provide machine-readable copies of all of our materials, in a
wide variety of electronic formats.
Byte Craft Limited can contribute to joint presentations at customer sites. Byte Craft
Limited staff travel around the world for client meetings, sales presentations, and
standards body participation.
Byte Craft Limited is located in Waterloo, Ontario, Canada. We are in the Eastern
Standard Time zone (EST/EDT, UTC-5).
Industry Presence
Byte Craft Limited sends representatives to selected embedded systems conferences. We
decide to attend trade shows on a case-by-case basis, and frequently present in conference
sessions. Contact us for more information.
Walter Banks participates in meetings of ISO
WG-14, the working group responsible for TR
Download demonstration versions of our
18037, Extensions for the Programming
products at:
Language C to support Embedded Processors.
http://www.bytecraft.com/depot/depot.php Walter's leadership has helped advance
Demonstration versions do not create embedded systems' support in the C language
executables, but do create listing files to standard.
allow inspection of generated code.
They come with full documentation and
tutorials.
DRAFT DOCUMENTATION 23
Byte Craft Limited DRAFT DOCUMENTATION
Publications
We have significant experience in publishing. Our website features two publications free
for download:
First Steps in Embedded Systems is a comprehensive general
text introducing embedded systems. Fuzzy Logic in Embedded
Microcomputers and Control Systems provides a tutorial on
fuzzy logic as it pertains to control systems. Both publications
can be downloaded from our website in PDF format.
To download: http://www.bytecraft.com/publishing.html
Product Development
Feedback and Improvements
Product development and technical support are intimately linked. The staff members
responsible for developing our Code Development Systems also provide front-line
technical support. Support calls or correspondence that reveals issues with the compiler
result in improvements to all of our products.
Toolchain Innovation
We work actively with simulator and emulator vendors to complete the developers'
toolchain. The Byte Craft Limited .COD file format and BCDIRECT embedded
connectivity links allow the compiler to communicate all necessary information to
downstream tools. We share standards documents on these technologies freely with other
vendors where mutual advantage exists.
Standards
Byte Craft Limited Code Development Systems conform to ISO standards for C as much
as possible for the target hardware platform. In many cases, a full implementation of
standard C is not possible.
A C standard for embedded systems (ISO Technical Report 18037) now formally makes
all of the processor registers, address spaces and internal flags available to the C
programmer. This makes it possible to match any assembly language statement in C. By
writing code in C and not assembly, every line of a program can benefit from the
compiler's optimization and data-flow analysis. This is a big advantage to developers.
Byte Craft's president Walter Banks represented Canada at ISO and was a major player in
the development of these standards.
24 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 25
Byte Craft Limited DRAFT DOCUMENTATION
Attachments
MC9RS08KA2 Device Header File
#ifndef __C6808DEF_H
#define __C6808DEF_H
/******************************************************************************
* *
* Byte Craft Limited C6808 Code Development System *
* *
******************************************************************************
* *
* Header file information: *
* *
* $ DeviceName: <ALL> $ *
* $ Manufacturer: FREESCALE $ *
* $ Filename: MC9RS08KA2.H $ *
* $ HeaderVer: 0.1 $ *
* $ Copyright: 2006 $ *
* $ Compiler: C6808 $ *
* $ CompilerVer: 2.0 $ *
* *
******************************************************************************/
#ifdef RS08_SECURE
#pragma fill @ 0x3FFC = 0x00;
#else
#pragma fill @ 0x3FFC = 0x01;
26 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
#endif /* RS_SECURE */
/* Registers */
#pragma regac AC; /* Accumulator A */
#pragma regix X; /* 0x000F */
/* Memory */
/*
||<--TINY-->|<------RAMPROG------>|
|0x0 0x0D|0x20 0x4F|
|---------------------------------|
<---------RAM------------------->
*/
/* tiny/small memory */
#pragma memory RAM tiny [0x0D] @ 0x00;
/* Interrupt vectors */
DRAFT DOCUMENTATION 27
Byte Craft Limited DRAFT DOCUMENTATION
/* Page register */
/* System options */
28 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* Flash options */
/* Pullup/pulldown enable */
DRAFT DOCUMENTATION 29
Byte Craft Limited DRAFT DOCUMENTATION
#define PTAPE1 1
#define PTAPE0 0
/* Pullup/pulldown control */
#endif /* __C6808DEF_H */
#include <MC9RS08KA2.h>
//quadrature encoder
/*
30 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
11 01 00 01
10 11 01 11
if ((state == 0b1101) ||
(state == 0b1011) ||
(state == 0b0010) ||
(state == 0b0100)) tally++;
else if ((state == 0b1110) ||
(state == 0b1000) ||
(state == 0b0001) ||
(state == 0b0111)) tally--;
KBIES = ~ save_port;
KBISC.KBACK = 1;
}
//detect edges
KBISC.KBIMOD = 0;
//enable pins
KBIPE |= 0x11;
//initialize transitions
KBIES = ~ PORTA;
//enable
KBISC.KBIE = 1;
void main(void)
{
QuadInit();
while(1)
{
__DISPATCH();
}
}
/******************************************************************************
DRAFT DOCUMENTATION 31
Byte Craft Limited DRAFT DOCUMENTATION
*
*
* $ File name : quadenc.c
$ *
* $ Description : Quadrature decoder.
$ *
******************************************************************************
*
*
*
*
* This routines may be adapted for any purpose when
*
* used with the Byte Craft Limited Code Development
*
* Systems. No warranty is implied or given as to
*
* their usability for any purpose.
*
*
*
* (c) Copyright 2006
*
* Byte Craft Limited
*
* A2-490 Dutton Drive
*
* Waterloo, Ontario
*
* Canada N2L 6H7
*
* (519) 888-6911
*
*
*
* Kirk Zurell
*
*
*
******************************************************************************
*
*
* Revision history
*
* $ V:1.0 KZ Mar 2006 Initial release
$ *
* $ V:1.1 WB APR 2006 Combined the state diagram into one
function $ *
*
*
******************************************************************************/
#include <MC9RS08KA2.h>
#ifndef __C6808DEF_H
0006 #define __C6808DEF_H
/******************************************************************************
*
*
* Byte Craft Limited C6808 Code Development System
*
*
*
******************************************************************************
*
*
* Header file information:
*
*
*
* $ DeviceName: <ALL>
$ *
* $ Manufacturer: FREESCALE
$ *
32 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
* $ Filename: MC9RS08KA2.H
$ *
* $ HeaderVer: 0.1
$ *
* $ Copyright: 2006
$ *
* $ Compiler: C6808
$ *
* $ CompilerVer: 2.0
$ *
*
*
******************************************************************************/
/******************************************************************************
*
*
DRAFT DOCUMENTATION 33
Byte Craft Limited DRAFT DOCUMENTATION
******************************************************************************
*
*
* Revision History:
*
* ~~~~~~~~~~~~~~~~~
*
* $ V:1.00 KZ 23/02/06 Initial version for RS08
$ *
* $ V:1.01 WB 18/03/06 Initial MC9RS08KA2
$ *
*
*
******************************************************************************
*
*
* Notes:
*
* ~~~~~~
*
* This is a generic header file that will work on many/most RS08
devices. *
* For more specific definitions, use the proper header file for
the device. *
*
*
* Deviations from datasheet:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* MTIMCLK.CLKS -> MTIMCLK.CLKSRC due to conflict with ICSC1 CLKS
*
* SIP1.LVD -> SIP1.LVDI due to conflict with SRS.LVD
*
*
*
* Aliases:
*
* ~~~~~~~~
*
* PTAD -> PORTA
*
*
*
******************************************************************************/
34 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
#ifdef RS08_SECURE
#pragma fill @ 0x3FFC = 0x00;
#else
3FFC 01 #pragma fill @ 0x3FFC = 0x01;
#endif /* RS_SECURE */
/* Registers */
0000 #pragma regac AC; /* Accumulator A */
0000 #pragma regix X; /* 0x000F */
/* Memory */
DRAFT DOCUMENTATION 35
Byte Craft Limited DRAFT DOCUMENTATION
/*
||<--TINY-->|<------RAMPROG------>|
|0x0 0x0D|0x20 0x4F|
|---------------------------------|
<---------RAM------------------->
*/
/* tiny/small memory */
0000 000D #pragma memory RAM tiny [0x0D] @ 0x00;
/* Interrupt vectors */
36 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 37
Byte Craft Limited DRAFT DOCUMENTATION
/* Page register */
/* System options */
38 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* Flash options */
DRAFT DOCUMENTATION 39
Byte Craft Limited DRAFT DOCUMENTATION
/* Pullup/pulldown enable */
/* Pullup/pulldown control */
#endif /* __C6808DEF_H */
//quadrature encoder
/*
40 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
11 10 00 10
10 00 01 00
if ((state == 0b1101) ||
(state == 0b1011) ||
3812 A1 0D CMP #$0D (state == 0b0010) ||
3814 37 0C BEQ $3822
3816 A1 0B CMP #$0B (state == 0b0100)) tally++;
3818 37 08 BEQ $3822
381A A1 02 CMP #$02
381C 37 04 BEQ $3822
381E A1 04 CMP #$04
3820 36 08 BNE $382A
3822 3C 21 INC $21
3824 36 02 BNE $3828
3826 3C 20 INC $20
3828 30 19 BRA $3843 else if ((state == 0b1110) ||
(state == 0b1000) ||
382A A1 0E CMP #$0E (state == 0b0001) ||
382C 37 0C BEQ $383A
382E A1 08 CMP #$08 (state == 0b0111)) tally--;
3830 37 08 BEQ $383A
3832 A1 01 CMP #$01
3834 37 04 BEQ $383A
3836 A1 07 CMP #$07
3838 36 09 BNE $3843
383A 4E 21 21 TST $21
383D 36 02 BNE $3841
DRAFT DOCUMENTATION 41
Byte Craft Limited DRAFT DOCUMENTATION
//detect edges
3854 11 1C BCLR 0,$1C KBISC.KBIMOD = 0;
//enable pins
3856 DD LDA $1D KBIPE |= 0x11;
3857 AA 11 ORA #$11
3859 FD STA $1D
//initialize transitions
385C D0 LDA $10 KBIES = ~ PORTA;
385D 43 COMA
385E FE STA $1E
//enable
385F 12 1C BSET 1,$1C KBISC.KBIE = 1;
3865 BE RTS }
void main(void)
{
3866 AD E2 BSR $384A QuadInit();
while(1)
3868 AD 02 BSR $386C {
42 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
386A __DISPATCH();
386A 30 FC BRA $3868 }
}
__DISPATCH:
386C AF WAIT
386D 09 C2 02 BRCLR 4,$0202,$3872
3870 30 8E BRA $3800
3872 BE RTS
__MAIN:
3FFD BC 38 66
DRAFT DOCUMENTATION 43
Byte Craft Limited DRAFT DOCUMENTATION
SYMBOL TABLE
44 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 45
Byte Craft Limited DRAFT DOCUMENTATION
Errors : 0
Warnings : 0
*/
#include <rs08def.h>
//to delete:
#define _Bool bit
//helpful definitions
#define true 1
#define false 0
void main(void)
{
unsigned int16 positivecount;
unsigned int16 totaltarget;
positivecount = 0;
calibrating = false;
46 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
totaltarget = totalstore;
//main loop
while(1)
{
if(comparator_hi())
{
positivecount++;
if(calibrating)
{
}
else
//not calibrating
{
//update display();
if(totalcount == totaltarget)
{
//positivecount contains voltage reading.
DRAFT DOCUMENTATION 47
Byte Craft Limited DRAFT DOCUMENTATION
#pragma option f 0;
*/
#include <rs08def.h>
#ifndef __C6808DEF_H
0006 #define __C6808DEF_H
/******************************************************************************
*
*
* Byte Craft Limited C6808 Code Development System
*
*
*
******************************************************************************
*
*
* Header file information:
*
*
*
* $ DeviceName: <ALL>
$ *
* $ Manufacturer: FREESCALE
$ *
* $ Filename: RS08DEF.H
$ *
* $ HeaderVer: 0.1
$ *
* $ Copyright: 2006
$ *
* $ Compiler: C6808
$ *
* $ CompilerVer: 2.0
$ *
*
*
******************************************************************************/
/******************************************************************************
*
*
* This code may be adapted for any purpose when
*
* used with the C6808 Code Development System.
*
48 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
******************************************************************************
*
*
* Revision History:
*
* ~~~~~~~~~~~~~~~~~
*
* $ V:1.00 KZ 23/02/06 Initial version for RS08
$ *
*
*
******************************************************************************
*
*
* Notes:
*
* ~~~~~~
*
* This is a generic header file that will work on many/most RS08
devices. *
* For more specific definitions, use the proper header file for
the device. *
*
*
* Deviations from datasheet:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* MTIMCLK.CLKS -> MTIMCLK.CLKSRC due to conflict with ICSC1 CLKS
*
* SIP1.LVD -> SIP1.LVDI due to conflict with SRS.LVD
*
*
*
* Aliases:
*
* ~~~~~~~~
*
* PTAD -> PORTA
*
*
*
******************************************************************************/
#ifdef RS08_SECURE
#pragma fill @ 0x3FFC = 0x00;
#else
3FFC 01 #pragma fill @ 0x3FFC = 0x01;
#endif /* RS_SECURE */
/* Registers */
0000 #pragma regac AC; /* Accumulator A */
0000 #pragma regix X; /* 0x000F */
DRAFT DOCUMENTATION 49
Byte Craft Limited DRAFT DOCUMENTATION
/* Memory */
/*
||<--TINY-->|<------RAMPROG------>|
|0x0 0x0D|0x20 0x4F|
|---------------------------------|
<---------RAM------------------->
*/
/* tiny/small memory */
0000 000D #pragma memory RAM tiny [0x0D] @ 0x00;
/* Interrupt vectors */
50 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* Page register */
/* System options */
DRAFT DOCUMENTATION 51
Byte Craft Limited DRAFT DOCUMENTATION
/* Flash options */
/* Pullup/pulldown enable */
/* Pullup/pulldown control */
52 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
#endif /* __C6808DEF_H */
//to delete:
000A #define _Bool bit
//helpful definitions
00000001 #define true 1
00000000 #define false 0
void main(void)
{
001F unsigned int16 positivecount;
001D unsigned int16 totaltarget;
DRAFT DOCUMENTATION 53
Byte Craft Limited DRAFT DOCUMENTATION
}
3847 30 14 BRA $385D else
//not calibrating
{
//update display();
__MAIN:
3FFD BC 38 00
SYMBOL TABLE
54 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 55
Byte Craft Limited DRAFT DOCUMENTATION
Errors : 0
Warnings : 0
This code may be adapted for any purpose when used with the Fuzz-C
fuzzy logic preprocessor. No warranty is implied or given as to
its usability for any purpose.
Revision History
56 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
dd mmm yyyy ii t
1993 WB First version
Oct 2005 KZ Comments
*/
/* proportional error */
LINGUISTIC Error TYPE int MIN -90 MAX 90
{
MEMBER LNegative { -90, -90, -20, 0 }
MEMBER normal { -20, 0, 20 }
MEMBER close { -3, 0, 3 }
MEMBER LPositive { 0, 20, 90, 90 }
}
FUZZY pid
{
/* large moves for large proportional errors */
IF Error IS LNegative THEN ManVar IS LPositive
IF Error IS LPositive THEN ManVar IS LNegative
DRAFT DOCUMENTATION 57
Byte Craft Limited DRAFT DOCUMENTATION
int OldError,SumError,Setpoint;
int Process(void) { return 1; } // Dummy Process
/* LINGUISTIC Error TYPE int MIN -90 MAX 90 */
/* { */
int Error ;
/* MEMBER LNegative { -90, -90, -20, 0 } */
/*
1-| .............
| . .
| . .
| . .
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char Error_LNegative (int __CRISP)
{
{
if (__CRISP <= -20) return(255);
else
{
if (__CRISP <= 0)
return(( - __CRISP * 12) + 7);
else
return(0);
}
}
}
/* MEMBER normal { -20, 0, 20 } */
/*
1-| .
| . .
| . .
| . .
0-| ............. .............
----------------------------------
-90 -45 0 45 90
58 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
*/
char Error_normal (int __CRISP)
{
if (__CRISP < -20) return(0);
else
{
if (__CRISP <= 0) return(((__CRISP + 20) * 12) + 7);
else
{
{
if (__CRISP <= 20)
return((( + 20 - __CRISP) * 12) + 7);
else
return(0);
}
}
}
}
/* MEMBER close { -3, 0, 3 } */
/*
1-| .
| .
| ..
| . .
0-| ................ ................
----------------------------------
-90 -45 0 45 90
*/
char Error_close (int __CRISP)
{
if (__CRISP < -3) return(0);
else
{
if (__CRISP <= 0) return((__CRISP + 3) * 85);
else
{
{
if (__CRISP <= 3)
return(( + 3 - __CRISP) * 85);
else
return(0);
}
}
}
}
/* MEMBER LPositive { 0, 20, 90, 90 } */
/*
1-| .............
| . .
| . .
| . .
0-| ................. .
----------------------------------
-90 -45 0 45 90
*/
char Error_LPositive (int __CRISP)
{
if (__CRISP < 0) return(0);
else
{
if (__CRISP <= 20) return((__CRISP * 12) + 7);
else
{
return(255);
}
}
}
/* } */
/*
DRAFT DOCUMENTATION 59
Byte Craft Limited DRAFT DOCUMENTATION
----------------------------------
-90 -45 0 45 90
*/
/* LINGUISTIC DeltaError TYPE int MIN -90 MAX 90 */
/* { */
int DeltaError ;
/* MEMBER Negative { -90, -90, -10, 0 } */
/*
1-| ...............
| . .
| . .
| . .
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char DeltaError_Negative (int __CRISP)
{
{
if (__CRISP <= -10) return(255);
else
{
if (__CRISP <= 0)
return(( - __CRISP * 25) + 2);
else
return(0);
}
}
}
/* MEMBER Positive { 0, 10, 90, 90 } */
/*
1-| ...............
| . .
| . .
| . .
0-| ................. .
----------------------------------
-90 -45 0 45 90
*/
char DeltaError_Positive (int __CRISP)
{
if (__CRISP < 0) return(0);
else
{
if (__CRISP <= 10) return((__CRISP * 25) + 2);
else
{
return(255);
}
}
}
/* } */
/*
*/
/* LINGUISTIC SumError TYPE int MIN -90 MAX 90 */
/* { */
/* MEMBER LNeg { -90, -90, -5, 0 } */
/*
1-| ................
| . .
| . .
| . .
60 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char SumError_LNeg (int __CRISP)
{
{
if (__CRISP <= -5) return(255);
else
{
if (__CRISP <= 0)
return( - __CRISP * 51);
else
return(0);
}
}
}
/* MEMBER LPos { 0, 5, 90, 90 } */
/*
1-| ................
| . .
| . .
| . .
0-| ................. .
----------------------------------
-90 -45 0 45 90
*/
char SumError_LPos (int __CRISP)
{
if (__CRISP < 0) return(0);
else
{
if (__CRISP <= 5) return(__CRISP * 51);
else
{
return(255);
}
}
}
/* } */
/*
*/
/* CONSEQUENCE ManVar TYPE int MIN -20 MAX 20 DEFUZZ cg */
/* { */
int ManVar ;
int fa_ManVar, fc_ManVar;
/* MEMBER LNegative { -18 } */
/*
1-| .
| .
| .
| .
0-| ..*..............................
----------------------------------
-20 -10 0 10 20
*/
void ManVar_LNegative (int __DOM)
{
fc_ManVar += __DOM;
fa_ManVar += (__DOM * (-18));
}
/* MEMBER SNegative { -6 } */
/*
DRAFT DOCUMENTATION 61
Byte Craft Limited DRAFT DOCUMENTATION
1-| .
| .
| .
| .
0-| ...........*.....................
----------------------------------
-20 -10 0 10 20
*/
void ManVar_SNegative (int __DOM)
{
fc_ManVar += __DOM;
fa_ManVar += (__DOM * (-6));
}
/* MEMBER SPositive { 6 } */
/*
1-| .
| .
| .
| .
0-| .....................*...........
----------------------------------
-20 -10 0 10 20
*/
void ManVar_SPositive (int __DOM)
{
fc_ManVar += __DOM;
fa_ManVar += (__DOM * (6));
}
/* MEMBER LPositive { 18 } */
/*
1-| .
| .
| .
| .
0-| ..............................*..
----------------------------------
-20 -10 0 10 20
*/
void ManVar_LPositive (int __DOM)
{
fc_ManVar += __DOM;
fa_ManVar += (__DOM * (18));
}
/* } */
/* FUZZY pid */
void pid (void)
{
fa_ManVar = 0;
fc_ManVar = 0;
/* { */
/* IF Error IS LNegative THEN ManVar IS LPositive */
ManVar_LPositive( Error_LNegative(Error) );
/* IF Error IS LPositive THEN ManVar IS LNegative */
ManVar_LNegative( Error_LPositive(Error) );
/* IF Error IS normal AND DeltaError IS Positive */
/* THEN ManVar IS SNegative */
__IDOM[1] = Error_normal(Error) ;
__IDOM[0] = DeltaError_Positive(DeltaError) ;
__IDOM[0] = F_AND(__IDOM[1],__IDOM[0]);
ManVar_SNegative( __IDOM[0] );
/* IF Error IS normal AND DeltaError IS Negative */
/* THEN ManVar IS SPositive */
__IDOM[1] = Error_normal(Error) ;
__IDOM[0] = DeltaError_Negative(DeltaError) ;
__IDOM[0] = F_AND(__IDOM[1],__IDOM[0]);
ManVar_SPositive( __IDOM[0] );
/* IF Error IS close AND SumError IS LPos */
/* THEN ManVar IS SNegative */
__IDOM[1] = Error_close(Error) ;
__IDOM[0] = SumError_LPos(SumError) ;
__IDOM[0] = F_AND(__IDOM[1],__IDOM[0]);
ManVar_SNegative( __IDOM[0] );
62 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
#include "MC9RS08KA2.h"
#ifndef __C6808DEF_H
0006 #define __C6808DEF_H
/******************************************************************************
*
*
* Byte Craft Limited C6808 Code Development System
*
*
*
******************************************************************************
*
*
* Header file information:
*
*
*
* $ DeviceName: <ALL>
$ *
* $ Manufacturer: FREESCALE
$ *
* $ Filename: MC9RS08KA2.H
$ *
* $ HeaderVer: 0.1
$ *
* $ Copyright: 2006
$ *
* $ Compiler: C6808
$ *
* $ CompilerVer: 2.0
$ *
*
*
******************************************************************************/
/******************************************************************************
*
*
* This code may be adapted for any purpose when
*
* used with the C6808 Code Development System.
*
* No warranty is implied or given as to their
*
DRAFT DOCUMENTATION 63
Byte Craft Limited DRAFT DOCUMENTATION
******************************************************************************
*
*
* Revision History:
*
* ~~~~~~~~~~~~~~~~~
*
* $ V:1.00 KZ 23/02/06 Initial version for RS08
$ *
* $ V:1.01 WB 18/03/06 Initial MC9RS08KA2
$ *
*
*
******************************************************************************
*
*
* Notes:
*
* ~~~~~~
*
* This is a generic header file that will work on many/most RS08
devices. *
* For more specific definitions, use the proper header file for
the device. *
*
*
* Deviations from datasheet:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* MTIMCLK.CLKS -> MTIMCLK.CLKSRC due to conflict with ICSC1 CLKS
*
* SIP1.LVD -> SIP1.LVDI due to conflict with SRS.LVD
*
*
*
64 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
* Aliases:
*
* ~~~~~~~~
*
* PTAD -> PORTA
*
*
*
******************************************************************************/
#ifdef RS08_SECURE
#pragma fill @ 0x3FFC = 0x00;
#else
3FFC 01 #pragma fill @ 0x3FFC = 0x01;
#endif /* RS_SECURE */
/* Registers */
0000 #pragma regac AC; /* Accumulator A */
0000 #pragma regix X; /* 0x000F */
/* Memory */
/*
||<--TINY-->|<------RAMPROG------>|
|0x0 0x0D|0x20 0x4F|
|---------------------------------|
<---------RAM------------------->
*/
/* tiny/small memory */
0000 000D #pragma memory RAM tiny [0x0D] @ 0x00;
/* Interrupt vectors */
DRAFT DOCUMENTATION 65
Byte Craft Limited DRAFT DOCUMENTATION
66 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* Page register */
DRAFT DOCUMENTATION 67
Byte Craft Limited DRAFT DOCUMENTATION
/* System options */
68 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
/* Flash options */
/* Pullup/pulldown enable */
/* Pullup/pulldown control */
DRAFT DOCUMENTATION 69
Byte Craft Limited DRAFT DOCUMENTATION
#endif /* __C6808DEF_H */
#include "fuzzc.h"
000000FF #define F_ONE 0xff
00000000 #define F_ZERO 0x00
000A #define F_OR(a,b) ((a) > (b) ? (a) : (b))
000B #define F_AND(a,b) ((a) < (b) ? (a) : (b))
000C #define F_NOT(a) (F_ONE+F_ZERO-a)
0020 0002 char __IDOM[2];
#pragma has RS08;
/* Fuzz-C Fuzzy Logic Preprocessor
70 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
1-| .............
| . .
| . .
| . .
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char Error_LNegative (int __CRISP)
004E {
3803 B7 45 STA $45
{
3805 A1 EC CMP #$EC if (__CRISP <= -20) return(255);
3807 B6 FF LDA $023F
3809 BE RTS
else
{
380A B6 45 LDA $45 if (__CRISP <= 0)
380C A1 00 CMP #$00
380E 43 COMA return(( - __CRISP * 12) + 7);
380F 4C INCA
3810 3E 0C 0F LDX #$0C
3813 BD 39 DF JSR $39DF
3816 AB 07 ADD #$07
3818 BE RTS
else
3819 4F CLRA return(0);
381A BE RTS
}
}
}
/* MEMBER normal { -20, 0, 20 } */
/*
1-| .
| . .
| . .
| . .
0-| ............. .............
----------------------------------
-90 -45 0 45 90
*/
char Error_normal (int __CRISP)
004E 004D {
381B B7 4D STA $4D
381D A1 EC CMP #$EC if (__CRISP < -20) return(0);
381F 4F CLRA
3820 BE RTS
else
{
DRAFT DOCUMENTATION 71
Byte Craft Limited DRAFT DOCUMENTATION
1-| .
| .
| ..
| . .
0-| ................ ................
----------------------------------
-90 -45 0 45 90
*/
char Error_close (int __CRISP)
004E 004D {
3845 B7 4D STA $4D
3847 A1 FD CMP #$FD if (__CRISP < -3) return(0);
3849 4F CLRA
384A BE RTS
else
{
384B B6 4D LDA $4D if (__CRISP <= 0) return((__CRISP + 3) * 85);
384D A1 00 CMP #$00
384F B6 03 LDA $03
3851 BB 4D ADD $4D
3853 3E 55 0F LDX #$55
3856 BD 39 DF JSR $39DF
3859 BE RTS
else
{
72 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
{
385A B6 4D LDA $4D if (__CRISP <= 3)
385C A1 03 CMP #$03
385E B6 03 LDA $03 return(( + 3 - __CRISP) * 85);
3860 B0 4D SUB $4D
3862 3E 55 0F LDX #$55
3865 BD 39 DF JSR $39DF
3868 BE RTS
else
3869 4F CLRA return(0);
386A BE RTS
}
}
}
}
/* MEMBER LPositive { 0, 20, 90, 90 } */
/*
1-| .............
| . .
| . .
| . .
0-| ................. .
----------------------------------
-90 -45 0 45 90
*/
char Error_LPositive (int __CRISP)
004E 004D {
386B B7 4D STA $4D
386D 0F 4D 02 BRCLR 7,$4D,$3872 if (__CRISP < 0) return(0);
3870 4F CLRA
3871 BE RTS
else
{
3872 B6 4D LDA $4D if (__CRISP <= 20) return((__CRISP * 12) + 7);
3874 A1 14 CMP #$14
3876 3E 0C 0F LDX #$0C
3879 BD 39 DF JSR $39DF
387C AB 07 ADD #$07
387E BE RTS
else
{
387F B6 FF LDA $023F return(255);
3881 BE RTS
}
}
}
/* } */
/*
DRAFT DOCUMENTATION 73
Byte Craft Limited DRAFT DOCUMENTATION
| . . ... .
| . . . . . .
0-| ............. ... .............
----------------------------------
-90 -45 0 45 90
*/
/* LINGUISTIC DeltaError TYPE int MIN -90 MAX 90 */
/* { */
0026 int DeltaError ;
/* MEMBER Negative { -90, -90, -10, 0 } */
/*
1-| ...............
| . .
| . .
| . .
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char DeltaError_Negative (int __CRISP)
004E 004D {
3882 B7 4D STA $4D
{
3884 A1 F6 CMP #$F6 if (__CRISP <= -10) return(255);
3886 B6 FF LDA $023F
3888 BE RTS
else
{
3889 B6 4D LDA $4D if (__CRISP <= 0)
388B A1 00 CMP #$00
388D 43 COMA return(( - __CRISP * 25) + 2);
388E 4C INCA
388F 3E 19 0F LDX #$19
3892 BD 39 DF JSR $39DF
3895 AB 02 ADD #$02
3897 BE RTS
else
3898 4F CLRA return(0);
3899 BE RTS
}
}
}
/* MEMBER Positive { 0, 10, 90, 90 } */
/*
1-| ...............
| . .
| . .
| . .
0-| ................. .
----------------------------------
74 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
-90 -45 0 45 90
*/
char DeltaError_Positive (int __CRISP)
004E 004D {
389A B7 4D STA $4D
389C 0F 4D 02 BRCLR 7,$4D,$38A1 if (__CRISP < 0) return(0);
389F 4F CLRA
38A0 BE RTS
else
{
38A1 B6 4D LDA $4D if (__CRISP <= 10) return((__CRISP * 25) + 2);
38A3 A1 0A CMP #$0A
38A5 3E 19 0F LDX #$19
38A8 BD 39 DF JSR $39DF
38AB AB 02 ADD #$02
38AD BE RTS
else
{
38AE B6 FF LDA $023F return(255);
38B0 BE RTS
}
}
}
/* } */
/*
*/
/* LINGUISTIC SumError TYPE int MIN -90 MAX 90 */
/* { */
/* MEMBER LNeg { -90, -90, -5, 0 } */
/*
1-| ................
| . .
| . .
| . .
0-| . .................
----------------------------------
-90 -45 0 45 90
*/
char SumError_LNeg (int __CRISP)
004E 004D {
DRAFT DOCUMENTATION 75
Byte Craft Limited DRAFT DOCUMENTATION
1-| ................
| . .
| . .
| . .
0-| ................. .
----------------------------------
-90 -45 0 45 90
*/
char SumError_LPos (int __CRISP)
004E 004D {
38C7 B7 4D STA $4D
38C9 0F 4D 02 BRCLR 7,$4D,$38CE if (__CRISP < 0) return(0);
38CC 4F CLRA
38CD BE RTS
else
{
38CE B6 4D LDA $4D if (__CRISP <= 5) return(__CRISP * 51);
38D0 A1 05 CMP #$05
38D2 3E 33 0F LDX #$33
38D5 BD 39 DF JSR $39DF
38D8 BE RTS
else
{
38D9 B6 FF LDA $023F return(255);
38DB BE RTS
}
}
}
/* } */
/*
76 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
*/
/* CONSEQUENCE ManVar TYPE int MIN -20 MAX 20 DEFUZZ cg */
/* { */
0027 int ManVar ;
0028 0029 int fa_ManVar, fc_ManVar;
/* MEMBER LNegative { -18 } */
/*
1-| .
| .
| .
| .
0-| ..*..............................
----------------------------------
-20 -10 0 10 20
*/
void ManVar_LNegative (int __DOM)
004E 004D {
38DC B7 4D STA $4D
38DE B6 29 LDA $29 fc_ManVar += __DOM;
38E0 BB 4D ADD $4D
38E2 B7 29 STA $29
38E4 B6 4D LDA $4D fa_ManVar += (__DOM * (-18));
38E6 3E EE 0F LDX #$EE
38E9 BD 39 DF JSR $39DF
38EC BB 28 ADD $28
38EE B7 28 STA $28
38F0 BE RTS }
/* MEMBER SNegative { -6 } */
/*
1-| .
| .
| .
| .
0-| ...........*.....................
----------------------------------
-20 -10 0 10 20
*/
void ManVar_SNegative (int __DOM)
DRAFT DOCUMENTATION 77
Byte Craft Limited DRAFT DOCUMENTATION
004E 004D {
38F1 B7 4D STA $4D
38F3 B6 29 LDA $29 fc_ManVar += __DOM;
38F5 BB 4D ADD $4D
38F7 B7 29 STA $29
38F9 B6 4D LDA $4D fa_ManVar += (__DOM * (-6));
38FB 3E FA 0F LDX #$FA
38FE BD 39 DF JSR $39DF
3901 BB 28 ADD $28
3903 B7 28 STA $28
3905 BE RTS }
/* MEMBER SPositive { 6 } */
/*
1-| .
| .
| .
| .
0-| .....................*...........
----------------------------------
-20 -10 0 10 20
*/
void ManVar_SPositive (int __DOM)
004E 004D {
3906 B7 4D STA $4D
3908 B6 29 LDA $29 fc_ManVar += __DOM;
390A BB 4D ADD $4D
390C B7 29 STA $29
390E B6 4D LDA $4D fa_ManVar += (__DOM * (6));
3910 3E 06 0F LDX #$06
3913 BD 39 DF JSR $39DF
3916 BB 28 ADD $28
3918 B7 28 STA $28
391A BE RTS }
/* MEMBER LPositive { 18 } */
/*
1-| .
| .
| .
| .
0-| ..............................*..
----------------------------------
-20 -10 0 10 20
*/
void ManVar_LPositive (int __DOM)
004E 004D {
391B B7 4D STA $4D
391D B6 29 LDA $29 fc_ManVar += __DOM;
391F BB 4D ADD $4D
3921 B7 29 STA $29
78 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 79
Byte Craft Limited DRAFT DOCUMENTATION
80 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 81
Byte Craft Limited DRAFT DOCUMENTATION
SYMBOL TABLE
82 DRAFT DOCUMENTATION
DRAFT DOCUMENTATION C6808 for Freescale RS08
DRAFT DOCUMENTATION 83
Byte Craft Limited DRAFT DOCUMENTATION
Errors : 0
Warnings : 0
84 DRAFT DOCUMENTATION