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

📄 le4.c

📁 freescale mc9rs08le4 C code with 3,5 digits lcd
💻 C
字号:
/** ###################################################################
**     Filename  : le4.C
**     Project   : le4
**     Processor : MC9RS08LE4CPC
**     Version   : Driver 01.01
**     Compiler  : CodeWarrior RS08 C Compiler
**     Date/Time : 20/1/2009, 14:18
**     Abstract  :
**         Main module.
**         This module contains user's application code.
**     Settings  :
**     Contents  :
**         No public methods
**
** ###################################################################*/
/* MODULE le4 */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "LCD1.h"
#include "AD1.h"
#include "SENSOR.h"
#include "RTI1.h"
#include "LEDS.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"
#include "comandos.h"

byte RamBuffer[22];

byte bpaPlace [ ] =
{
	Char1a,   
	Char1b,   
	Char1c,   
	Char1d,   
	Char1e,   
	Char1f,   
	Char1g,   
	Char2a,   
	Char2b,   
	Char2c,   
	Char2d,   
	Char2e,   
	Char2f,   
	Char2g,
};

const byte baAscii [ ] =
{
	_0
	_1
	_2
	_3
	_4
	_5
	_6
	_7
	_8
	_9
};

struct{
  unsigned lobat:1;
  unsigned cinco:1;
  unsigned zero:1;
  unsigned bloq:5;
}x;

word val=0,val_ant,med=0,s, temp=0,voga, cont=0,y;
dword sum=0;
byte nvezes_maior=0,nvezes_menor=0,medd=10;
//************************************************************************
void wr(byte lbValue)
{
byte bLCD_CharPosition = 0;
byte *lbpLCDWF = &LCDWFRef;
byte lbOffset=0;
byte lbCounter=14,i=0,n;
byte *lbpLCDWFCopy = &RamBuffer[0];
word vec[3]={0,0,0};

LCDWF8=1;

if(lbValue>70){
  lbValue=70;
}

for(;lbValue/10;i++){
  vec[i]=lbValue%10;
	lbValue=lbValue/10;
}
	vec[i]=lbValue;
	
   while (lbCounter--)
   {
     if(lbCounter>6){
      i=1;
      n=7;
     }else{
      i=0;
      n=0;
     }
     lbOffset = bpaPlace[bLCD_CharPosition];						//Find the Waveform offset
     *(lbpLCDWFCopy + lbOffset) = 0;
     *(lbpLCDWFCopy + lbOffset) |= (baAscii[vec[i]]>>(lbCounter-n));
     *(lbpLCDWF + lbOffset) = *(lbpLCDWFCopy + lbOffset);			//Write the value to the waveform
     bLCD_CharPosition++;           
   }
	 if(x.lobat){
	   segment(10,1);
	 }else{
	   segment(10,0);
	 }
   segment(6,1);//corpo do numero sempre asceso
	 if(x.zero){
	   segment(7,1);
	 }else{
	   segment(7,0);
	 }
	 if(x.cinco){
	   segment(9,1);//g3
	 }else{
	   segment(9,0);//g3
	 }
          
   
  
}
//************************************************************************
void main(void)
{
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

x.zero=1;
x.cinco=0;
LCDWF8=1;
segment(1,1);//g1
segment(3,1);//g2

for(;;){

temp=0;
sum=0;
cont=0;

for(s=0;s<1000;s++){//7.5*xms=7.5s
   _Stop;
   RTI1_Init();
//   Cpu_Delay100US(60);


    (void)AD1_Measure(1);
    (void)AD1_GetValue(&val);
      sum+=val;
      cont++;


//=====================================================================
if(med&&!x.bloq){
//=====================================================================
     if(val>med&&nvezes_maior<10){//barco desacelerando (valor aumentando +Z)
      if(val>val_ant){
        nvezes_maior++;

        if(nvezes_maior==medd){//dispara timer
           voga=5000-((76*temp)/10);
           voga/=10;
           y=voga/10;
           y*=10;
           
           if((voga-y)>4){
             x.cinco=1;
             x.zero=0;
           }else{
             x.cinco=0;
             x.zero=1;
           }

           voga/=10;
           wr((byte)voga);
           sum=0;
           cont=0;
           s=0;
           x.bloq=31;

           if(Cpu_GetLowVoltageFlag()){
             Cpu_ClearLowVoltageFlag();
             x.lobat=1;
           }else{
             x.lobat=0;
           } 
          nvezes_menor=0;
          temp=0;
        }

      }else{//n鉶 continuou acelerando = pegada falsa
        nvezes_maior=0;
      }
     }else
//=====================================================================    
     if(val<med){
      if(val<val_ant){//barco acelerando (valor diminui -Z)
        nvezes_menor++;
        if(nvezes_menor==medd){
           nvezes_maior=0;
        }
      }
     }
//=====================================================================    
val_ant=val;
}//(med)=====================================================================

temp++;
if(x.bloq){
  x.bloq--;
}
}//(for)=====================================================================

if(s==1000){
  wr(0);
  x.zero=1;
  x.cinco=0;
  med=sum/cont;
  val_ant=med;
  cont=0;
  sum=0;
}
  



//contador++;

/*if(contador>10){//entra em modo stop
  SRTISC_RTIS=0;  
  LCDC0_LCDEN=0;
  SENSOR_ClrVal();
  _Stop;
} */
}
  /*** 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 le4 */
/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.04 [04.19]
**     for the Freescale RS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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