
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.robotika.sk/robowiki/index.php?action=history&amp;feed=atom&amp;title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program</id>
		<title>Frc Demo.c Ukážkový program - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.robotika.sk/robowiki/index.php?action=history&amp;feed=atom&amp;title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program"/>
		<link rel="alternate" type="text/html" href="https://wiki.robotika.sk/robowiki/index.php?title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program&amp;action=history"/>
		<updated>2026-05-19T17:52:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://wiki.robotika.sk/robowiki/index.php?title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program&amp;diff=4147&amp;oldid=prev</id>
		<title>Balogh at 21:44, 24 March 2009</title>
		<link rel="alternate" type="text/html" href="https://wiki.robotika.sk/robowiki/index.php?title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program&amp;diff=4147&amp;oldid=prev"/>
				<updated>2009-03-24T21:44:58Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 21:44, 24 March 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;code &lt;/del&gt;lang=&amp;quot;c&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;source &lt;/ins&gt;lang=&amp;quot;c&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;/******************************************************************************&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;/******************************************************************************&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l421&quot; &gt;Line 421:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 421:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; } /* loop forever */&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; } /* loop forever */&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;code&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;source&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Balogh</name></author>	</entry>

	<entry>
		<id>https://wiki.robotika.sk/robowiki/index.php?title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program&amp;diff=4146&amp;oldid=prev</id>
		<title>Balogh: New page: &lt;code lang=&quot;c&quot;&gt; /****************************************************************************** * * Freescale Semiconductor Inc. * (c) Copyright 2008 Freescale Semiconductor, Inc. * ALL RI...</title>
		<link rel="alternate" type="text/html" href="https://wiki.robotika.sk/robowiki/index.php?title=Frc_Demo.c_Uk%C3%A1%C5%BEkov%C3%BD_program&amp;diff=4146&amp;oldid=prev"/>
				<updated>2009-03-24T21:43:47Z</updated>
		
		<summary type="html">&lt;p&gt;New page: &amp;lt;code lang=&amp;quot;c&amp;quot;&amp;gt; /****************************************************************************** * * Freescale Semiconductor Inc. * (c) Copyright 2008 Freescale Semiconductor, Inc. * ALL RI...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;code lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
*&lt;br /&gt;
* Freescale Semiconductor Inc.&lt;br /&gt;
* (c) Copyright 2008 Freescale Semiconductor, Inc.&lt;br /&gt;
* ALL RIGHTS RESERVED.&lt;br /&gt;
*&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*&lt;br /&gt;
* File      main.c&lt;br /&gt;
*&lt;br /&gt;
* Author    Milan Brejl&lt;br /&gt;
* &lt;br /&gt;
* Version   0.2&lt;br /&gt;
* &lt;br /&gt;
* Date      19-Nov-2008&lt;br /&gt;
* &lt;br /&gt;
* Brief     Quick start with the Self-Driven Slot Car development&lt;br /&gt;
*&lt;br /&gt;
*******************************************************************************&lt;br /&gt;
* History:&lt;br /&gt;
* 0.1 (14-Oct-2008) Initial version&lt;br /&gt;
* 0.2 (19-Nov-2008) &lt;br /&gt;
*******************************************************************************&lt;br /&gt;
*&lt;br /&gt;
* This file includes initialization code and macros enabling to quickly start&lt;br /&gt;
* with the development of a Self-Driven Slot Car.&lt;br /&gt;
*&lt;br /&gt;
* At the current state, the application branches into one of 2 modes, based on&lt;br /&gt;
* the slot car vertical position. If the car is placed on the track, it slowly&lt;br /&gt;
* starts up, drives the car by a 50% voltage, samples all analog signals (motor&lt;br /&gt;
* current, X, Y, and Z accelerations, and DC-Bus voltage) and stores the X&lt;br /&gt;
* acceleration into the EEPROM. In the wheels-up position, detected using the&lt;br /&gt;
* gravitational acceleration in Z axis, the data from EEPROM can be downloaded&lt;br /&gt;
* into an Excel sheet using the ReadEEPROM.pmp FreeMASTER project.&lt;br /&gt;
*&lt;br /&gt;
* Notes:&lt;br /&gt;
* 1) The MCU S08JM32 is configured to run at 48MHz CPU clock and 24MHz BUS &lt;br /&gt;
*    clock. &lt;br /&gt;
*    The OSBDM debugger can be used to program the flash and run the  &lt;br /&gt;
*    application, but it can not step and break the code at such a high rate.&lt;br /&gt;
* 2) The motor is controlled in one direction only, using a motorVoltage&lt;br /&gt;
*    unsigned int variable (range 0 to 6000) and a PWM signal of corresponding&lt;br /&gt;
*    duty-cycle. &lt;br /&gt;
*    In order to control the motor in both directions (active breaking), the&lt;br /&gt;
*    initialization of the TPM1 module needs to be modified for a generation of&lt;br /&gt;
*    2 PWM signals. For more information refer to the MC33887 H-bridge manual.&lt;br /&gt;
* 3) The external EEPROM is handled by the Jaroslav Necesany's driver &lt;br /&gt;
*    eeprom.c/.h, included into the project.&lt;br /&gt;
*&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;hidef.h&amp;gt;          /* for EnableInterrupts macro */&lt;br /&gt;
#include &amp;quot;derivative.h&amp;quot;     /* include peripheral declarations */&lt;br /&gt;
#include &amp;quot;slotcarutils.h&amp;quot;   /* utilities */&lt;br /&gt;
#include &amp;quot;eeprom.h&amp;quot;         /* driver for external EEPROM via IIC */&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
* Constants and macros&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
/* LEDs */&lt;br /&gt;
/* &lt;br /&gt;
 * There are 4 LEds build into the head and break lights.&lt;br /&gt;
 *   HL = head light - left, HR = head light - right, &lt;br /&gt;
 *   BL = break light - left, BR = break light - right &lt;br /&gt;
 * The following macros control the LEDs state, ON or OFF.&lt;br /&gt;
 */&lt;br /&gt;
#define SET_LED_HL_ON          PTAD_PTAD0 = 1&lt;br /&gt;
#define SET_LED_HL_OFF         PTAD_PTAD0 = 0&lt;br /&gt;
#define SET_LED_HR_ON          PTAD_PTAD1 = 1&lt;br /&gt;
#define SET_LED_HR_OFF         PTAD_PTAD1 = 0&lt;br /&gt;
#define SET_LED_BL_ON          PTAD_PTAD2 = 1&lt;br /&gt;
#define SET_LED_BL_OFF         PTAD_PTAD2 = 0&lt;br /&gt;
#define SET_LED_BR_ON          PTAD_PTAD3 = 1&lt;br /&gt;
#define SET_LED_BR_OFF         PTAD_PTAD3 = 0&lt;br /&gt;
&lt;br /&gt;
/* SWITCH */&lt;br /&gt;
/*&lt;br /&gt;
 * There is a 2-position switch.&lt;br /&gt;
 * The following macro reads the switch position, returning 1 or 0.&lt;br /&gt;
 */&lt;br /&gt;
#define GET_SWITCH_STATE       PTCD_PTCD6&lt;br /&gt;
&lt;br /&gt;
/* ACCELEROMETER */&lt;br /&gt;
/*&lt;br /&gt;
 * There is a 3-axis accelerometer with analog outputs.&lt;br /&gt;
 * The accelerometer range is configurable for either +/- 1.5g or +/- 6g.&lt;br /&gt;
 * The accelerometer analog outputs can be sampled by the on-chip Analog-to-&lt;br /&gt;
 * -Digital Converter.&lt;br /&gt;
 * The following macros set the accelerometer range and define the ADC &lt;br /&gt;
 * channels of the X, Y and Z accelerometer outputs:&lt;br /&gt;
 *   X ... left and right (+ left, - right)&lt;br /&gt;
 *   Y ... ahead and back (+ ahead, - back)&lt;br /&gt;
 *   Z ... up and down (+ down, - up)&lt;br /&gt;
 */&lt;br /&gt;
#define SET_ACC_RANGE_1_5_G    PTCD_PTCD2 = 0&lt;br /&gt;
#define SET_ACC_RANGE_6_G      PTCD_PTCD2 = 1&lt;br /&gt;
#define ACC_X                  2&lt;br /&gt;
#define ACC_Y                  1&lt;br /&gt;
#define ACC_Z                  0&lt;br /&gt;
&lt;br /&gt;
/* MOTOR */&lt;br /&gt;
/*&lt;br /&gt;
 * There is an H-brigde driving the DC motor.&lt;br /&gt;
 * The motor drive can be enabled or disabled. When enabled, the applied motor&lt;br /&gt;
 * voltage is controlled by a PWM duty-cycle.&lt;br /&gt;
 * The H-brigde circuit returns a fault status in case of undervoltage,&lt;br /&gt;
 * short circuit, or overtemperature condition.&lt;br /&gt;
 * The motor current feedback can be sampled by the on-chip Analog-to-Digital&lt;br /&gt;
 * Converter.&lt;br /&gt;
 * The following macros enable or disable the motor drive, set the motor &lt;br /&gt;
 * voltage, get the motor fault status and define the ADC channel of&lt;br /&gt;
 * the motor current.&lt;br /&gt;
 */&lt;br /&gt;
#define MOTOR_ENABLE           PTCD_PTCD4 = 1&lt;br /&gt;
#define MOTOR_DISABLE          PTCD_PTCD4 = 0&lt;br /&gt;
#define SET_MOTOR_VOLTAGE(x)   TPM1C2V = (x)&lt;br /&gt;
#define GET_MOTOR_VOLTAGE      TPM1C2V&lt;br /&gt;
#define GET_MOTOR_FAULT_STATUS PTGD_PTGD2&lt;br /&gt;
#define MOTOR_STATUS_OK        1&lt;br /&gt;
#define MOTOR_STATUS_FAULT     0&lt;br /&gt;
#define MOTOR_CURRENT          5&lt;br /&gt;
&lt;br /&gt;
/* DC-BUS VOLTAGE */&lt;br /&gt;
/*&lt;br /&gt;
 * There is a circuit which enables to measure the DC-Bus voltage.&lt;br /&gt;
 * The DC-Bus Voltage Compensation technique enables to set a correct motor &lt;br /&gt;
 * voltage and keep it independent of a the actual DC-Bus voltage.&lt;br /&gt;
 * The following macros defines the ADC channel of the DC-Bus voltage.&lt;br /&gt;
 */&lt;br /&gt;
#define DC_BUS_VOLTAGE         11&lt;br /&gt;
&lt;br /&gt;
/* ADC */&lt;br /&gt;
/*&lt;br /&gt;
 * The following macros enable to initializes the sampling and &lt;br /&gt;
 * conversion of an analog signal a defined read a conversion result - a 12-bit sample,&lt;br /&gt;
 * to check if the Analog-to-Digital Converter is busy by an active conversion, and&lt;br /&gt;
 * switch conversion resolution (8/10/12-bit mode)&lt;br /&gt;
 */&lt;br /&gt;
#define START_CONV(channel)    ADCSC1 = ADCSC1_AIEN_MASK | (channel)&lt;br /&gt;
#define READ_ADC_SAMPLE        ADCR&lt;br /&gt;
#define GET_ADC_ACTIVE_FLAG    ADCSC2_ADACT&lt;br /&gt;
#define SET_ADC_MODE_8_BIT     ADCCFG_MODE = 0&lt;br /&gt;
#define SET_ADC_MODE_10_BIT    ADCCFG_MODE = 2&lt;br /&gt;
#define SET_ADC_MODE_12_BIT    ADCCFG_MODE = 1&lt;br /&gt;
&lt;br /&gt;
/* OUTAGE */&lt;br /&gt;
/*&lt;br /&gt;
 * There is a circuit which enables to detect a power supply outage&lt;br /&gt;
 * on the line change or crossover track pieces.&lt;br /&gt;
 */&lt;br /&gt;
#define GET_OUTAGE_DIR1        PTGD_PTGD0&lt;br /&gt;
#define GET_OUTAGE_DIR2        PTGD_PTGD1&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
* Global variables&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
/* application */&lt;br /&gt;
enum {&lt;br /&gt;
  APP_MODE_RUN,&lt;br /&gt;
  APP_MODE_DOWNLOAD&lt;br /&gt;
} appMode;&lt;br /&gt;
&lt;br /&gt;
/* accelerometer */&lt;br /&gt;
unsigned int accX, accY, accZ;   /* 12-bit unsigned samples */&lt;br /&gt;
&lt;br /&gt;
/* motor */&lt;br /&gt;
unsigned int motorVoltage;       /* range 0 to 6000 */&lt;br /&gt;
unsigned int motorCurrent;       /* 12-bit unsigned sample */&lt;br /&gt;
&lt;br /&gt;
/* dc-bus */&lt;br /&gt;
unsigned int dcBus;              /* 12-bit unsigned sample */&lt;br /&gt;
&lt;br /&gt;
/* global time */&lt;br /&gt;
unsigned int timeCounter;        /* global free-running 1/2ms counter */&lt;br /&gt;
&lt;br /&gt;
/* extern global variables */&lt;br /&gt;
extern enum SEMAPHORE semaphore1;&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
* Functions&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
* Interrupt Handlers&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
/* Timer/PWM Interrupt */&lt;br /&gt;
interrupt VectorNumber_Vtpm1ovf void Vtpm1ovf_isr(void) &lt;br /&gt;
{&lt;br /&gt;
  /* clear interrupt flag */&lt;br /&gt;
  TPM1SC_TOF = 0;&lt;br /&gt;
  &lt;br /&gt;
  /* update PWM duty-cycle according to the global variable motorVoltage */&lt;br /&gt;
  SET_MOTOR_VOLTAGE(motorVoltage);&lt;br /&gt;
  &lt;br /&gt;
  /* Start sequence of analog inputs sampling */&lt;br /&gt;
  START_CONV(MOTOR_CURRENT);&lt;br /&gt;
  &lt;br /&gt;
  /* Update the global 1/2ms timeCounter */&lt;br /&gt;
  timeCounter++;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* ADC Conversion Complete Interrupt */&lt;br /&gt;
interrupt VectorNumber_Vadc void Vadc_isr(void)&lt;br /&gt;
{&lt;br /&gt;
  /* &lt;br /&gt;
   * Read the new sample using GET_ADC_SAMPLE macro.&lt;br /&gt;
   * The reading also clears the interrupt flag.&lt;br /&gt;
   * Put all samples into the buffer.&lt;br /&gt;
   */&lt;br /&gt;
  switch(ADCSC1_ADCH)&lt;br /&gt;
  {&lt;br /&gt;
  case MOTOR_CURRENT:&lt;br /&gt;
    motorCurrent = READ_ADC_SAMPLE;&lt;br /&gt;
    START_CONV(ACC_X);&lt;br /&gt;
    break;&lt;br /&gt;
  case ACC_X:&lt;br /&gt;
    accX = READ_ADC_SAMPLE;&lt;br /&gt;
    START_CONV(ACC_Y);&lt;br /&gt;
    PutToBuffer16(accX);  /* store accX to EEPROM */&lt;br /&gt;
    break;&lt;br /&gt;
  case ACC_Y:&lt;br /&gt;
    accY = READ_ADC_SAMPLE;&lt;br /&gt;
    START_CONV(ACC_Z);&lt;br /&gt;
    break;&lt;br /&gt;
  case ACC_Z:&lt;br /&gt;
    accZ = READ_ADC_SAMPLE;&lt;br /&gt;
    START_CONV(DC_BUS_VOLTAGE);&lt;br /&gt;
    break;&lt;br /&gt;
  case DC_BUS_VOLTAGE:&lt;br /&gt;
    dcBus = READ_ADC_SAMPLE;&lt;br /&gt;
    break;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Keyboard Interrupt */&lt;br /&gt;
interrupt VectorNumber_Vkeyboard void Vkeyboard_isr(void)&lt;br /&gt;
{&lt;br /&gt;
  /* clear interrupt flag */&lt;br /&gt;
  KBISC_KBACK=1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/******************************************************************************&lt;br /&gt;
* Main&lt;br /&gt;
******************************************************************************/&lt;br /&gt;
&lt;br /&gt;
void main(void) &lt;br /&gt;
{&lt;br /&gt;
  /********** Device Initialization **********/&lt;br /&gt;
&lt;br /&gt;
  /* initialize the Multi-Purpose Clock Generator (MCG) &lt;br /&gt;
     for 48MHz CPU clock and 24MHz bus clock */&lt;br /&gt;
  MCGC2 = 0x36;   /* MCGC2: BDIV=0,RANGE=1,HGO=1,LP=0,EREFS=1,ERCLKEN=1,EREFSTEN=0 */&lt;br /&gt;
  MCGC1 = 0xB8;   /* MCGC1: CLKS=2,RDIV=7,IREFS=0,IRCLKEN=0,IREFSTEN=0 */&lt;br /&gt;
  while(!MCGSC_OSCINIT);  /* Wait until external reference is stable */&lt;br /&gt;
  while(MCGSC_IREFST);    /* Wait until external reference is selected */&lt;br /&gt;
  while((MCGSC &amp;amp; 0x0C) != 0x08);  /* Wait until external clock is selected as a bus clock reference */&lt;br /&gt;
  MCGC2 = 0x3E;   /* MCGC2: BDIV=0,RANGE=1,HGO=1,LP=1,EREFS=1,ERCLKEN=1,EREFSTEN=0 */&lt;br /&gt;
  MCGC1 = 0x88;   /* MCGC1: CLKS=2,RDIV=1,IREFS=0,IRCLKEN=0,IREFSTEN=0 */&lt;br /&gt;
  MCGC3 = 0x46;   /* MCGC3: LOLIE=0,PLLS=1,CME=0,VDIV=6 */&lt;br /&gt;
  MCGC2 &amp;amp;= (unsigned char)~0x08;   /* MCGC2: LP=0 */&lt;br /&gt;
  while(!MCGSC_PLLST);    /* Wait until PLL is selected */&lt;br /&gt;
  while(!MCGSC_LOCK);     /* Wait until PLL is locked */&lt;br /&gt;
  MCGC1 = 0x08;   /* MCGC1: CLKS=0,RDIV=1,IREFS=0,IRCLKEN=0,IREFSTEN=0 */&lt;br /&gt;
  while((MCGSC &amp;amp; 0x0C) != 0x0C);  /* Wait until PLL clock is selected as a bus clock reference */&lt;br /&gt;
&lt;br /&gt;
  /* disable the COP watchdog */&lt;br /&gt;
  SOPT1_COPT = 0;&lt;br /&gt;
  &lt;br /&gt;
  /* initialize the LEDs as outputs */&lt;br /&gt;
  PTADD_PTADD0 = 1; /* output to LED1 */&lt;br /&gt;
  PTADD_PTADD1 = 1; /* output to LED2 */&lt;br /&gt;
  PTADD_PTADD2 = 1; /* output to LED3 */&lt;br /&gt;
  PTADD_PTADD3 = 1; /* output to LED4 */&lt;br /&gt;
&lt;br /&gt;
  /* initialize the SWITCH as an input with pull-up */&lt;br /&gt;
  PTCDD_PTCDD6 = 0; /* input from switch */&lt;br /&gt;
  PTCPE_PTCPE6 = 1; /* pull-up enable */&lt;br /&gt;
&lt;br /&gt;
  /* initialize the ACCELEROMETER range select as an output */&lt;br /&gt;
  PTCDD_PTCDD2 = 1; /* output to G-select */&lt;br /&gt;
  &lt;br /&gt;
  /* initialize the MOTOR driver inputs as outputs */&lt;br /&gt;
  PTCDD_PTCDD4 = 1; /* output to EN */&lt;br /&gt;
  PTADD_PTADD5 = 1; /* output to D1 */&lt;br /&gt;
  PTADD_PTADD4 = 1; /* output to D2 */&lt;br /&gt;
  PTFDD_PTFDD2 = 1; /* output to IN2 */&lt;br /&gt;
  &lt;br /&gt;
  /* initialize the MOTOR driver fault status output as an input */&lt;br /&gt;
  PTFDD_PTFDD1 = 0; /* input from fault status */&lt;br /&gt;
  &lt;br /&gt;
  /* initialize TPM1 for PWM generation */&lt;br /&gt;
  TPM1SC = 0;&lt;br /&gt;
  TPM1MOD = 6000;     /* Modulo = 6000 =&amp;gt; f = 24MHz/1/(6000*2) = 2kHz */&lt;br /&gt;
  TPM1SC_CLKSx = 1;   /* clock source = bus clock */&lt;br /&gt;
  TPM1SC_PS = 0;      /* prescaler divider = 1 */&lt;br /&gt;
  TPM1SC_CPWMS = 1;   /* center-aligned PWM */&lt;br /&gt;
  TPM1C2SC_ELS2x = 2; /* low-true pulses */&lt;br /&gt;
  TPM1SC_TOIE = 1;    /* enable overflow interrupt */&lt;br /&gt;
&lt;br /&gt;
  /* initialize the ADC */&lt;br /&gt;
  ADCCFG_ADICLK = 1;/* input clock = bus clock divided by 2 */&lt;br /&gt;
  ADCCFG_ADIV = 1;  /* input clock div = 2 */&lt;br /&gt;
  ADCCFG_ADLSMP = 1;/* long sample time enabled */&lt;br /&gt;
  ADCCFG_MODE = 1;  /* 12-bit mode */&lt;br /&gt;
  ADCSC2_ADTRG = 0; /* software trigger */&lt;br /&gt;
  APCTL1_ADPC0 = 1; /* pin ADP0 is ADC input - accelerometer Z */&lt;br /&gt;
  APCTL1_ADPC1 = 1; /* pin ADP1 is ADC input - accelerometer Y */&lt;br /&gt;
  APCTL1_ADPC2 = 1; /* pin ADP2 is ADC input - accelerometer X */&lt;br /&gt;
  APCTL1_ADPC5 = 1; /* pin ADP5 is ADC input - motor current */&lt;br /&gt;
  APCTL2_ADPC11 = 1; /* pin ADP11 is ADC input - dc-bus voltage */&lt;br /&gt;
  &lt;br /&gt;
  /* initialize Keyboard Interrupt to detect outage */&lt;br /&gt;
  KBIES_KBEDG0 = 0;  /* detect falling edge from OUTAGE_DIR1 */&lt;br /&gt;
  KBIES_KBEDG1 = 0;  /* detect falling edge from OUTAGE_DIR2 */&lt;br /&gt;
  KBISC_KBMOD = 0;   /* detect edge only */&lt;br /&gt;
  KBIPE_KBIPE0 = 1;  /* enable OUTAGE_DIR1 pin interrupt */&lt;br /&gt;
  KBIPE_KBIPE1 = 1;  /* enable OUTAGE_DIR2 pin interrupt */&lt;br /&gt;
  KBISC_KBIE = 1;    /* enable interrupts */&lt;br /&gt;
  &lt;br /&gt;
  /* enable interrupts */&lt;br /&gt;
  EnableInterrupts;&lt;br /&gt;
&lt;br /&gt;
  /************ Board HW Initialization *************/&lt;br /&gt;
&lt;br /&gt;
  /* initialize the Accelerometr */&lt;br /&gt;
  SET_ACC_RANGE_1_5_G;&lt;br /&gt;
&lt;br /&gt;
  /* initialize the Motor H-bridge driver */&lt;br /&gt;
  PTAD_PTAD5 = 0;  /* set D1 low */&lt;br /&gt;
  PTAD_PTAD4 = 1;  /* set D2 high */&lt;br /&gt;
  PTFD_PTFD2 = 0;  /* set IN2 low */&lt;br /&gt;
  MOTOR_DISABLE;&lt;br /&gt;
  motorVoltage = 0;&lt;br /&gt;
&lt;br /&gt;
  /* initialize EEPROM */&lt;br /&gt;
  EepromInit(0x45);  /* 400kbit/sec at 24MHz Bus clock */&lt;br /&gt;
&lt;br /&gt;
  /************* Start-up *************/&lt;br /&gt;
&lt;br /&gt;
  /* indicate the actual switch position */&lt;br /&gt;
  Wait(1000);&lt;br /&gt;
  if(GET_SWITCH_STATE == 1)&lt;br /&gt;
  {&lt;br /&gt;
    /* blink front lights once */&lt;br /&gt;
    SET_LED_HL_ON;&lt;br /&gt;
    SET_LED_HR_ON;&lt;br /&gt;
    Wait(300);&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    /* blink front lights twice */&lt;br /&gt;
    SET_LED_HL_ON;&lt;br /&gt;
    SET_LED_HR_ON;&lt;br /&gt;
    Wait(100);&lt;br /&gt;
    SET_LED_HL_OFF;&lt;br /&gt;
    SET_LED_HR_OFF;&lt;br /&gt;
    Wait(100);&lt;br /&gt;
    SET_LED_HL_ON;&lt;br /&gt;
    SET_LED_HR_ON;&lt;br /&gt;
    Wait(100);&lt;br /&gt;
  }&lt;br /&gt;
  SET_LED_HL_OFF;&lt;br /&gt;
  SET_LED_HR_OFF;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
  /* test if the car is in the wheels up position and set application mode */&lt;br /&gt;
  if (accZ &amp;gt; 2048)&lt;br /&gt;
  {&lt;br /&gt;
    appMode = APP_MODE_DOWNLOAD;&lt;br /&gt;
    DisableInterrupts;&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    appMode = APP_MODE_RUN;&lt;br /&gt;
    /* slowly speed up */&lt;br /&gt;
    MOTOR_ENABLE;&lt;br /&gt;
    while(motorVoltage &amp;lt;= 3000)&lt;br /&gt;
    {&lt;br /&gt;
      motorVoltage++;&lt;br /&gt;
      Wait(1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /************* Background Loop *************/&lt;br /&gt;
  for(;;) &lt;br /&gt;
  {&lt;br /&gt;
    switch(appMode)&lt;br /&gt;
    {&lt;br /&gt;
    case APP_MODE_DOWNLOAD:&lt;br /&gt;
      /* Download buffer from EEPROM if empty */&lt;br /&gt;
      LoadBufferFromEeprom();&lt;br /&gt;
      /* Show page-by-page downloading on break LEDs */&lt;br /&gt;
      if (semaphore1)&lt;br /&gt;
      {&lt;br /&gt;
        SET_LED_BR_ON;&lt;br /&gt;
        SET_LED_BL_OFF;&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
        SET_LED_BR_OFF;&lt;br /&gt;
        SET_LED_BL_ON;&lt;br /&gt;
      }&lt;br /&gt;
      break;&lt;br /&gt;
&lt;br /&gt;
    case APP_MODE_RUN:&lt;br /&gt;
      /* Upload buffer to EEPROM if filled up */&lt;br /&gt;
      StoreBufferToEeprom();&lt;br /&gt;
      /* Check motor fault status */&lt;br /&gt;
      if(GET_MOTOR_FAULT_STATUS == MOTOR_STATUS_FAULT)&lt;br /&gt;
      {&lt;br /&gt;
        motorVoltage = 0;&lt;br /&gt;
        SET_LED_BL_ON;&lt;br /&gt;
        SET_LED_BR_ON;&lt;br /&gt;
      }&lt;br /&gt;
      break;&lt;br /&gt;
    }&lt;br /&gt;
  } /* loop forever */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Balogh</name></author>	</entry>

	</feed>