基于C8051F的AD UART0 KEY FLASH TIME3程序
// Main.c
//------------------------------------------------------------------------------------
// Copyright (C) 2011 Shenyang 213.
// Wbr
// Tool chain: KEIL Full c
//
//#pragma CD OE DB SB // Compilation directives
//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#include "C8051F340.h"
#include "1302.h"
#include "lcd.h"
#include
#define SYSCLK 12000000 // SYSCLK frequency in Hz
//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------
#define uint unsigned int
#define uchar unsigned char
#define T 1800 //運(yùn)算電量的時(shí)間單位1800是半個(gè)小時(shí)(1800秒)
#define N 11
sfr16 TMR2 = 0xCC; //定義成16位地址
sfr16 ADC0 = 0xBD;
uint xdata ADCbuffer1[N];
uint count;
uint sum = 0;
uchar ADcount = 0;
uchar ADsend;
uchar Page = 1,direction = 1;
uchar set = 0,ent = 0,Tset;
uchar TH,TL,TT1,TT2,TT3; //用來(lái)拆分送顯示的變量
uchar keybuffer[6];
uchar BGset=0; //BGset背光關(guān),開控制量,如果沒有鍵按下超過1分鐘,關(guān)閉背光!有鍵按下立刻開背光
bit Disptime,PDD;
sbit DI1 = P0^0 ;
sbit DI2 = P0^1 ;
sbit DE = P0^6 ;
sbit BLK = P0^7 ; //LCD背光
sbit JC1 = P2^7 ;
sbit JC2 = P3^1 ;
sbit JC3 = P3^2 ;
sbit JC4 = P3^3 ;
sbit DI3 = P3^6 ;
sbit DI4 = P3^7 ;
uchar code CPT_c[20] _at_ 0x8000; //7k的地址左右//充電時(shí)間要存入的FLASH地址,保存3天的時(shí)間和功率
uchar xdata CPT_x[20] _at_ 0x8000;
uchar code FPT_c[20] _at_ 0x8200; //7k的地址左右//放電時(shí)間要存入的FLASH地址,保存3天的時(shí)間和功率
uchar xdata FPT_x[20] _at_ 0x8200;
uchar xdata Between[20]; //0~11時(shí)間12~19存功率
////////////////////////////////////
extern void Init_Device(void);
extern uchar time_buf1[8] ;
uchar code tab1[]={
"實(shí)時(shí)電壓:"
};
uchar code tab2[]={
"實(shí)時(shí)電流:"
};
uchar code tab3[]={
"實(shí)時(shí)功率:"
};
uchar code tab4[]={
"運(yùn)行狀態(tài):"
};
uchar code tab5[]={
"歷史充電記錄"
};
uchar code tab6[]={
"歷史放電記錄"
};
uchar code tab7[]={
"當(dāng)前時(shí)間"
};
uchar code tab8[]={
"修改時(shí)間"
};
uchar code tab9[]={
"暫無(wú)記錄"
};
uchar code run1[]={
"停機(jī)"
};
uchar code run2[]={
"充電"
};
uchar code run3[]={
"放電"
};
uchar code run4[]={
"故障"
};
//uchar code run5[]={
//"系統(tǒng)故障信息"
//};
uchar code run5[]={
"感謝您的使用"
};
uchar code run6[]={
"本日累計(jì)充電"
};
uchar code run7[]={
"本日累計(jì)放電"
};
uchar code run8[]={
"版本號(hào):V1.0"
};
uchar xdata TAB[11]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x20};//數(shù)字0~9及顯示空白0x20
//----------------------------------------
// Function PROTOTYPES
//----------------------------------------
void delayms(uint ms)
{
uint Temp;
while(ms--)
{
Temp=1000;
while(Temp--);
{
//PCA0CPH2 = 1;
}
}
}
/*void Timer2_Init(int count2s)
{
TMR2CN = 0x00;
TMR2L = -count2s;
TMR2 = 0xffff;
ET2 = 1;
TR2 = 1;
}*/
//================================
//中值濾波程序
//================================
void filter()
{
static uchar count,i,j;
uint value_buf[N];
uint temp;
sum=0;
for(count=0;count
{
value_buf[count] = ADCbuffer1[count];;
}
for (j=0;j
{
for (i=0;i
{
if ( value_buf[i]>value_buf[i+1] )
{
temp = value_buf[i];
value_buf[i] = value_buf[i+1];
value_buf[i+1] = temp;
}
}
}
for(count=1;count
sum += value_buf[count];
}
void Uart0_SendData(uchar dat0)
{
SBUF0=dat0; //寫SBUF0,開始發(fā)送
while(TI0==0); //等待發(fā)送
TI0=0; //清發(fā)送標(biāo)志位
}
void Flash_Erase_CTP() //flash擦除充電時(shí)間和功率
{
EA =0;
VDM0CN = 0x80; // 使能VDD監(jiān)視器
RSTSRC = 0x02; // 上電復(fù)位VDD監(jiān)視器復(fù)位標(biāo)志
FLSCL=0X80; // 使能FLASH單穩(wěn)態(tài)定時(shí)器,F(xiàn)LASH讀時(shí)間SYSCLK<=25MHz
FLKEY = 0xA5; // 寫入關(guān)鍵字
FLKEY = 0xF1; // 寫入關(guān)鍵字
PSCTL |= 0x03; //允許擦,允許寫
CPT_x[0] = 0;
PSCTL &= ~0x03; //禁止寫,禁止擦
//EA = 1;
}
void Flash_Program_CTP() //flash寫入充電時(shí)間時(shí)間和功率
{
uchar j;
EA =0;
//Flash_Erase_CTP();
VDM0CN = 0x80; //使能VDD監(jiān)視器
RSTSRC = 0x02; //上電復(fù)位/VDD監(jiān)視器復(fù)位標(biāo)志
FLSCL=0X80; //使能FLASH單穩(wěn)態(tài)定時(shí)器,F(xiàn)LASH讀時(shí)間SYSCLK<=25MHz
PSCTL |= 0x01; //write enable
for(j =0;j<20;j++)
{
FLKEY = 0xa5;
FLKEY = 0xf1;
CPT_x[j] = Between[j];
//delayms(30);
}
PSCTL &= ~0x01; //禁止寫
EA = 1;
}
//***********************************
void Flash_Erase_FTP() //flash擦除放電時(shí)間和功率
{
EA =0;
VDM0CN = 0x80; // 使能VDD監(jiān)視器
RSTSRC = 0x02; // 上電復(fù)位VDD監(jiān)視器復(fù)位標(biāo)志
FLSCL=0X80; // 使能FLASH單穩(wěn)態(tài)定時(shí)器,F(xiàn)LASH讀時(shí)間SYSCLK<=25MHz
FLKEY = 0xA5; // 寫入關(guān)鍵字
FLKEY = 0xF1; // 寫入關(guān)鍵字
PSCTL |= 0x03; //允許擦,允許寫
FPT_x[0] = 0;
PSCTL &= ~0x03; //禁止寫,禁止擦
//EA = 1;
}
void Flash_Program_FTP() //flash寫入放電時(shí)間和功率
{
uchar j;
//Flash_Erase_FTP();
EA = 0;
VDM0CN = 0x80; //使能VDD監(jiān)視器
RSTSRC = 0x02; //上電復(fù)位/VDD監(jiān)視器復(fù)位標(biāo)志
FLSCL=0X80; //使能FLASH單穩(wěn)態(tài)定時(shí)器,F(xiàn)LASH讀時(shí)間SYSCLK<=25MHz
PSCTL|=0x01; //write enable
for(j =0;j<20;j++)
{
FLKEY = 0xa5;
FLKEY = 0xf1;
FPT_x[j] = Between[j];
}
PSCTL &= ~0x01; //禁止寫
EA = 1;
}
/*void Flash_Read()
{
static uchar j;
for(j=0;j<3;j++)
{
timer[j]=Ftime_c[j];
}
關(guān)鍵詞:
C8051FADUART0TIME
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論