?? copy of le4.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 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 baixou:1;
unsigned passou:1;
unsigned ini:1;
unsigned lobat:1;
unsigned cinco:1;
unsigned zero:1;
unsigned dispara:1;
}x;
word val=0,med=0,s, temp=0,voga, cont=0,y,medd;
dword sum=0;
byte yy=0;
//************************************************************************
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(;;){
x.baixou=0;
x.passou=0;
temp=0;
sum=0;
cont=0;
for(s=0;s<1600;s++){//800*xms=6s
// _Stop;
// RTI1_Init();
Cpu_Delay100US(80);
(void)AD1_Measure(1);
(void)AD1_GetValue(&val);
sum+=val;
cont++;
if(med&&val>(med+medd)){
if(x.dispara&&x.baixou){
x.passou=1;
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;
if(Cpu_GetLowVoltageFlag()){
Cpu_ClearLowVoltageFlag();
x.lobat=1;
}else{
x.lobat=0;
}
wr((byte)voga);
temp=0;
sum=0;
cont=0;
x.baixou=0;
x.passou=0;
s=0;
// break;//provoca saida
}
x.dispara=1;
}
if(med&&val<(med-medd)&&x.dispara){
x.dispara=0;
x.baixou=1;
}
if(x.dispara||x.baixou){
temp++;
}
}
if(s==1600&&!x.passou){
wr(0);
x.zero=1;
x.cinco=0;
med=sum/cont;
medd=med/70;
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.
**
** ###################################################################
*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -