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

📄 dy.c

📁 XML6122V4金旅电压表程序 XML6122V4金旅电压表程序 XML6122V4金旅电压表程序 XML6122V4金旅电压表程序
💻 C
字号:
/** ###################################################################
**     Filename  : dy.C
**     Project   : dy
**     Processor : MC9S08QD4CSC
**     Version   : Driver 01.11
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2008-2-26, 9:12
**     Abstract  :
**         Main module.
**         Here is to be placed user's code.
**     Settings  :
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/
/* MODULE dy */
/*************************************************************
模块名称:金旅副起动控制盒电压表程序
文件名称:main.c
模块描述:该模块对应的pcb,将595的latch管脚同时也作为第三位
          数码管的位选端,无须加电容进行滤波。595的H端作为
          第一位数码管的位选端,在显示第一位数码管时,应将其
          锁为高电平,其余为低电平。本模块沿袭翟抒群的程序框
          架,李亮针对公司编程规范进行了部分改写。并使程序量小
          于1.5k。
开发记录:
-------------------------------
日期         版本      行为人     行为
2006-07-14   0.0       李亮       改写翟工程序,调试通过
2006-07-15   1.0       李亮       按照规范进行改写程序
2007-01-05   2.0       李亮       改写程序
2008-02-26   3.0       李亮       QT2换为QD4
-------------------------------
*************************************************************/

/*************************************************************
说明AD值的计算方法
//5.1/(27+5.1)*x=5,x=31.47.31.47/0xff=x/ad
//x=ad*0.1234,x=1.234*ad=ad+ad/5+ad*3/100+?
*************************************************************/

/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Events.h"
#include "AD1.h"
#include "WDog1.h"
#include "Bit1.h"
#include "Bit2.h"
#include "Bit3.h"
#include "Bit4.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

typedef unsigned char  INT8U;
typedef unsigned int   INT16U;

																								   

#define IN_595     PTAD_PTAD0   
#define LATCH_595  PTAD_PTAD1   
#define LED3       PTAD_PTAD1   
#define SHIFT_595  PTAD_PTAD2   
#define LED2       PTAD_PTAD4   

/*INT8U ucDisplay[11] =
    {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x79};  */


void Write595(INT8U vucDisplayByte, INT8U ShowBit)
{

  //INT8U ucTemp;
  //SHIFT_595 = 0;

  LATCH_595 = 0;

  switch(vucDisplayByte)
  {
    case 0:
      vucDisplayByte = 0x3F;
      break;
    case 1:
      vucDisplayByte = 0x06;
      break;
    case 2:
      vucDisplayByte = 0x5B;
      break;
    case 3:
      vucDisplayByte = 0x4F;
      break;
    case 4:
      vucDisplayByte = 0x66;
      break;
    case 5:
      vucDisplayByte = 0x6D;
      break;
    case 6:
      vucDisplayByte = 0x7D;
      break;
    case 7:
      vucDisplayByte = 0x07;
      break;
    case 8:
      vucDisplayByte = 0x7F;
      break;
    case 9:
      vucDisplayByte = 0x6F;
      break;
    default:
      vucDisplayByte = 0x00;
  }
  if(ShowBit == 1) 
  {
    vucDisplayByte |= 0x80;
  }
  for(ShowBit=0; ShowBit<8; ShowBit++)
  {
	  if((vucDisplayByte & 0x80)!=0)
	  {
		  IN_595 = 1;
 	  }
 	  else
 	  {
		  IN_595 = 0;
	  }
	  SHIFT_595 = 0;
	  vucDisplayByte <<= 1;
	  SHIFT_595 = 1;
  }
  LATCH_595 = 1;
	LATCH_595 = 0;	  
}

void WaitNus(void)
{
  INT8U  ucTemp;
  
  for(ucTemp = 0; ucTemp < 30; ucTemp++)
  {
     WDog1_Clear();
  }
  
}

void main(void)
{
  /* Write your local variable definition here */
  INT8U ucADValue, ucTemp1, ucTemp2;
  INT8U ucShowNum1, ucShowNum2, ucShowNum3;
  INT16U wVoltage;
  
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  //EnableInterrupts; /* enable interrupts */
  
  LED2 = 1;
  LATCH_595 = 0;

  for(;;) 
  {
    WDog1_Clear(); /* feeds the dog */
    
    ucTemp1=AD1_Measure(1);
    ucTemp1=AD1_GetValue8(&ucADValue);
    
    ucTemp1 =  ucADValue / 5;    
    ucTemp2 =  (byte)(ucADValue * 3 / 100); 
    wVoltage = ucADValue + ucTemp1 + ucTemp2 + 8;  
    ucShowNum1 = (byte)(wVoltage/100); 
    ucShowNum2 = (byte)((wVoltage - ucShowNum1 * 100)/10);
    ucShowNum3 = (byte)(wVoltage - ucShowNum1 * 100 - ucShowNum2 * 10); 

    for(ucTemp1 = 0; ucTemp1 < 60; ucTemp1++)
    {
      
      //LED2 = 0;           
      Write595(ucShowNum1 , 1);    
      // WaitNus();	 
      Write595(ucShowNum2 , 2);
      LED2 = 0;
      WaitNus();
      LED2 = 1;
      Write595(ucShowNum3 , 3);            
      LATCH_595 = 1;        
      WaitNus();      
      //for(ucTemp2 = 0; ucTemp2 < 20; ucTemp2++);//调整亮度
      
      Write595(10 , 3);
            
      for(ucTemp2 = 0; ucTemp2 < 120; ucTemp2++)
      {        
        WaitNus();
      }
    }
    
  } /* loop forever */
  

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END dy */
/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.00 [03.89]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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