⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo9s08aw60_app.c

📁 FREESCALE 9S08AW60 程序实例
💻 C
字号:
/******************************************************************************
*
*       Copyright (C) 2006 Freescale Semiconductor, Inc.
*       All Rights Reserved
*
* Filename:     DEMO9S08AW60_APP.c
* Author:       Daniel Kruczek 
* Revision:     3.0
*
* Description:	Provides a demonstration of all of the peripherals on the DEMO9S08AW60E board.
*               
*                1.  Make sure the AW60 silicon is installed in the socket U3 with pin 1 in the bottom left
*                    hand corner towards the USB connector J33.
*                2.  Connect the USB cable, the USB, PWR_OUT, and VDD LEDs should be on.
*                3.  Connect a serial cable to the PC and then to the board.
*                4.  Open up a terminal window from within Windows XP by clicking on Start --> All
*                    Programs --> Accessories --> Communications --> HyperTerminal
*                5.  Give your terminal connection a name (such as DEOM9S08AW60_APP) and click the
*                    "OK" button.
*                6.  In the "Connect using" pulldown, select the COM port you connected your serial cable
*                    to, and click the "OK" button.
*                7.  In the "Port Settings" window, enter the following settings: Bits per second: 9600, Data
*                    bits: 8, Parity: None, Stop bits: 1, Flow control: None. Click the "OK" button.
*                8.  From within the Freescale CodeWarrior window, click on "Debug" under Project in the
*                    menu bar or press "F5". The True-Time Simulator& Real-Time Debugger interface
*                    window will appear.
*                9.  When the ICD Connection Assistant appears, click the "Connect" button.
*                10. When the "Erase and Program Flash?" window appears, click the "Yes" button.
*                11. The "CPROGHCS08 Programmer" window should close after the MCU FLASH is
*                    programmed. To run the DEMO9S08AW60_APP code, click on "Start/Continue"
*                    under Run in the menu bar or click the green arrow.
*                12. From the terminal window you set up in steps 7 through 10, you can type characters
*                    in your terminal window and they will be echoed. Type "x" when you are ready to move
*                    onto the LED/switch demo.
*                13. Toggle dip switches 0-7 on SW5 to toggle LEDs 0-7 on the lightbar. Press SW1 when
*                    you are ready to move on to the push button switch demo.
*                14. Press SW2 and SW3 to see LEDs 0 and 1 on the lightbar light up. Press SW4 when
*                    you are ready to move on to the potentiometer demo.
*                15. Values will be displayed in the terminal window based on the A to D input of the
*                    potentiometer. Rotate the Potentiometer (VR1) and watch the values change. Press
*                    SW1 when you are ready to move onto the photocell demo.
*                16. Values will be displayed in the terminal window based on the amount of light sensed
*                    by the photocell IC (U4). Vary the amount of light available to the photocell and watch
*                    the values change. Press SW4 when you are ready to move on to the accelerometer
*                    demo.
*                17. Two columns of values will be displayed in the terminal window. The first is the X
*                    output of the accelerometer (U5) the second is the Y output. Move the
*                    DEMO9S08AW60E in the X and Y directions to see the values change. Press SW1 to
*                    complete the demo.
*
* Notes:        Created using CodeWarrior 5.0 for HC(S)08.
******************************************************************************/

// ===================================================================
// Macro Functions definitions
// ===================================================================
// The setting in project preference must be checked
//   char should be unsigned 8 bit

typedef	unsigned char	muint8;
typedef	unsigned short	muint16;
typedef	unsigned long	muint32;

typedef	char			mint8;
typedef	short			mint16;
typedef	long			mint32;

// To Clear or Set single bits in a byte variable.
#define	b_SetBit(bit_ID, varID)		(varID |= (muint8)(1<<bit_ID))
#define	b_ClearBit(bit_ID, varID)	(varID &= ~(muint8)(1<<bit_ID))
#define	b_XorBit(bit_ID, varID)		(varID ^= (muint8)(1<<bit_ID))

// To Clear or Set single bits in a word(16-bit) variable.
#define	w_SetBit(bit_ID, varID)		(varID |= (muint16)(1<<bit_ID))
#define	w_ClearBit(bit_ID, varID)	(varID &= ~(muint16)(1<<bit_ID))
#define	w_XorBit(bit_ID, varID)		(varID ^= (muint16)(1<<bit_ID))

// To check single bit status in a given variable in ZERO PAGE
#define	b_CheckBit(bit_ID, varID)	(varID & (muint8)(1<<bit_ID))
#define	w_CheckBit(bit_ID, varID)(varID & (muint16)(1<<bit_ID))

// To check single bit status in a given variable in ZERO PAGE
#define		DummyRead(varID)			{__asm lda varID;}



/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "debug.h"
//#include "IO_Map.h"


#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08AW60.h> /* include peripheral declarations */

void main(void) {
  
  
  unsigned char       char_in=0;
  unsigned short      atod_in; 
 	unsigned short      atodx_in;
 	unsigned short      atody_in;
  
   
  EnableInterrupts; /* enable interrupts */
  /* include your code here */
  
  SOPT   = 0x00;			 // Disable COP	
  
  _INIT_DEBUG();     // Initiate the serial debug port
  
  // Begin serial port test
  
#if 1				         

  _DEBUGT("You can type characters and they will be echoed. To move on to the LED/switch test test, type x:");
 
  while (char_in != 'x') {
 
  char_in=_DEBUGREAD;
  _DEBUGWRITECHAR(char_in);
  
};

// Begin LED/Switch test

  _DEBUGT("\r\n Toggle the Dip Switches on SW5 to see the LEDs on LED1 toggle. Push SW1 to move on to the push button test");

PTCDD = 0x10;  // set port c as inputs for push button switch input except for C4 which is accelerometer ST
PTCPE = 0xEF;  // enable port c pullups for push button switch operation except for C4 which is accelerometer ST

PTDDD = 0x00;  // set port d as inputs for push button switch and accelerometer inputs
PTDPE = 0x0C;  // enable port d pullups on D2 and D3 for push button switch operation

PTADD = 0x00;  // set port a as inputs for dip switch input
PTAPE = 0xFF;  // enable port a pullups for dip switch operation


PTFDD = 0xFF;	 // set port f as outputs for dip switch input
PTFD = 0x0F;

while (PTCD_PTCD2==0x01) {	  
	 													
	 
	  if (PTAD_PTAD0==0x00)
    	b_ClearBit(0,PTFD);
    else
    	b_SetBit(0,PTFD);
    
    if (PTAD_PTAD1==0x00)
    	b_ClearBit(1,PTFD);
    else
    	b_SetBit(1,PTFD);
    
    if (PTAD_PTAD2==0x00)
    	b_ClearBit(2,PTFD);
    else
    	b_SetBit(2,PTFD);
    
    if (PTAD_PTAD3==0x00)
    	b_ClearBit(3,PTFD);
    else
    	b_SetBit(3,PTFD);
    
    if (PTAD_PTAD4==0x00)
    	b_ClearBit(4,PTFD);
    else
    	b_SetBit(4,PTFD);
    
    if (PTAD_PTAD5==0x00)
    	b_ClearBit(5,PTFD);
    else
    	b_SetBit(5,PTFD);
    
    if (PTAD_PTAD6==0x00)
    	b_ClearBit(6,PTFD);
    else
    	b_SetBit(6,PTFD);
    
    if (PTAD_PTAD7==0x00)
    	b_ClearBit(7,PTFD);
    else
    	b_SetBit(7,PTFD);
 
}


_DEBUGT("\r\n Push SW2 and SW3 to see LEDs on LED1 toggle. Push SW4 to move on to the potentiometer test.");

while (PTDD_PTDD2==0x01) {	  
	 													
	  if (PTCD_PTCD6==0x01)
    	b_ClearBit(0,PTFD);
    else
    	b_SetBit(0,PTFD);
    
    if (PTDD_PTDD3==0x01)
    	b_ClearBit(1,PTFD);
    else
    	b_SetBit(1,PTFD);  
    
}


// Begin potentiometer test

  _DEBUGT("\r\n Begin the potentiometer test. Push SW1 to move on to the photo cell test.");
     
  APCTL2  = 0x01;   // Disable IO control for ADPC8
 
  AD1SC1  = 0x28;   // Set the ADCO bit so continuous conversions are enabled
                    // Select AD8 as the input channel
                    
  while (PTCD_PTCD2==0x01) {  // Perform potentiometer test until SW1 is pressed 
  
    while (AD1SC1_COCO == 0); // Wait for a conversion to be completed  
    
      atod_in = AD1R;
      _DEBUGC((unsigned char)atod_in);
      _DEBUGT("\r\n");
  
  }
  
// Begin photo cell test

  _DEBUGT("\r\n Begin the photo cell test. Push SW4 to move on to the accelerometer test.");
     
  APCTL2  = 0x02;   // Disable IO control for ADPC9
 
  AD1SC1  = 0x29;   // Set the ADCO bit so continuous conversions are enabled
                    // Select AD9 as the input channel
                    
  while (PTDD_PTDD2==0x01) {  // Perform photo cell test until SW4 is pressed 
  
    while (AD1SC1_COCO == 0); // Wait for a conversion to be completed  
    
      atod_in = AD1R;
      _DEBUGC((unsigned char)atod_in);
      _DEBUGT("\r\n");
  
  }
  
// Begin accelerometer cell test

  _DEBUGT("\r\n Begin the accelerometer cell test. Push SW1 to end test.");
  APCTL2  = 0x30;      // Disable IO control for ADPC12 and ADPC13
  PTCD_PTCD4 = 0x00;	 // Set C4 low to keep accelerometer from going into self test
 
  while (PTCD_PTCD2==0x01) {  // Perform accelerometer test until SW1 is pressed 
  
    AD1SC1  = 0x0D;           // Select AD13 as the input channel
    while (AD1SC1_COCO == 0); // Wait for a conversion to be completed  
    atodx_in = AD1R;          // Store value in atodx_in
    _DEBUGC((unsigned char)atodx_in);        // Output value to terminal
    
    AD1SC1  = 0x0C;           // Select AD12 as the input channel
    while (AD1SC1_COCO == 0); // Wait for a conversion to be completed  
    atody_in = AD1R;					// Store value in atodx_in
    _DEBUGC((unsigned char)atody_in);				// Output value to terminal
          
    _DEBUGT("\r\n");					// Add line feeds
  
  }
  
  
_DEBUGT("\r\n All tests have been completed. Close the True-Time debugger and disconnect the USB and Serial cables. \r\n");

#endif 	 


  for(;;) {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -