📄 hldkzqv12.c
字号:
/*############################################################################
鼎立照明 16级灰度护栏灯控制器程序
创建时间:2004-07-01
硬件资源:
RAM ADDRESS :0000H---7FFFH
FLASH ADDRESS:8000H---8FFFH
CPLD ADDRESS:9000H---FFFFH
RAM SIZE :32K FLASH SIZE:8MBYTE = 4K*512PAGE*4PCS
2004-07-09 :测试程序
******************************************************************/
#include <reg52.h>
#include <intrins.h>
//#include <ctype.h>//字符函数
#include <string.h>//字符串函数
#include <stdio.h>//一般I/O函数
#include <stdlib.h>//标准函数
//#include <math.h>//数学函数
#include <absacc.h>//绝对地址
#include <intrins.h>//内部函数
#include <setjmp.h>
#define uchar unsigned char
#define uint unsigned int
#define byte unsigned char
#define word unsigned
#define bool bit
#define TRUE 1
#define FALSE 0
#define V_TH0 0xff /* 时间常数高8位 (65536-500)/256 */
#define V_TL0 0xff /* 时间常数低8位 (65536-500)%256 11.0592*/
//#define V_TH0 (65536-1536)/256
//#define V_TL0 (65536-1536)%256
#define V_TMOD 0x01 /* 定时器T0方式控制字 */
#define WriteDeviceAddress 0xa0
#define ReadDviceAddress 0xa1
/* 定义定时器T0的时间常数值和方式控制字 */
#define REGL XBYTE[0x9003] //控制寄存器护栏管的长度
#define FPGH XBYTE[0x9001] //闪存页高位
#define FPGL XBYTE[0x9002] //闪存页低位
//**********************************************
sbit senden=P3^2;
sbit SDA=P3^3;
sbit SCL=P3^5;
sbit wdgclr=P1^7;
//*************************************************
uint zhepe; //帧频
uint ms; //毫秒定时
uchar ADD; //地址
uchar idata send_buf[73]; //接收缓冲区
uchar pointer,subchk; //接收指针 和校验
uchar paklen; //包长
uint page_sta,page_end; //显示的开始帧和结束帧
uint dis_page; //当前显示的帧号
uint page; //扇区号
uchar bdata flag;
sbit frameok=flag^0; //rece ok
sbit color=flag^1; //0 sing red color 1 red green color
sbit rec_sta=flag^2; //1 进入接状态,不显示
sbit rec_end=flag^3;
sbit timout=flag^4;
//jmp_buf env;
//int retval;
/***************************************************************************/
void I2cDelay(unsigned int number) {
unsigned char temp;
for(;number!=0;number--,wdgclr=!wdgclr) {
for(temp=112;temp!=0;temp--) {
}
}
}
/***************************************************************************/
void Start() {
SDA=1;
SCL=1;
SDA=0;
SCL=0;
}
/***************************************************************************/
void Stop() {
SCL=0;
SDA=0;
SCL=1;
SDA=1;
}
/***************************************************************************/
void Ack() {
SDA=0;
SCL=1;
SCL=0;
SDA=1;
}
/***************************************************************************/
void NoAck() {
SDA=1;
SCL=1;
SCL=0;
}
/***************************************************************************/
bit TestAck() {
bit ErrorBit;
SDA=1;
SCL=1;
ErrorBit=SDA;
SCL=0;
return(ErrorBit);
}
/***************************************************************************/
Write8Bit(unsigned char input)
{
unsigned char temp;
for(temp=8;temp!=0;temp--) {
SDA=(bit)(input&0x80);
SCL=1;
SCL=0;
input=input<<1;
}
}
/***************************************************************************/
void Write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number) {
Start();
Write8Bit(WriteDeviceAddress);
TestAck();
Write8Bit(RomAddress);
TestAck();
for(;number!=0;number--) {
Write8Bit(*Wdata);
TestAck();
Wdata++;
}
Stop();
I2cDelay(10);
}
/***************************************************************************/
unsigned char Read8Bit() {
unsigned char temp,rbyte=0;
for(temp=8;temp!=0;temp--) {
SCL=1;
rbyte=rbyte<<1;
rbyte=rbyte|((unsigned char)(SDA));
SCL=0;
}
return(rbyte);
}
/***************************************************************************/
void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes) {
// unsigned char temp,rbyte;
Start();
Write8Bit(WriteDeviceAddress);
TestAck();
Write8Bit(RomAddress);
TestAck();
Start();
Write8Bit(ReadDviceAddress);
TestAck();
while(bytes!=1) {
*RamAddress=Read8Bit();
Ack();
RamAddress++;
bytes--;
}
*RamAddress=Read8Bit();
NoAck();
Stop();
}
/***************************************************************************/
//*******************************************
//从FLASH加载数据到RAM, flash -> ram 000
//入口参数:帧号 取值范围:0--8095
//******************************************
//#pragma NOMODDP2
void load_data(uint page)
{
uchar xdata *s;
uchar xdata *sp;
uchar xdata *rp;
sp=((page<<10)&0x0fff)|0x8000;
FPGH=(page>>2)/256;FPGL=(page>>2)%256;
s=0x000;
//for(i=0;i<1024;i++)*s++=*sp++;
rp=memcpy(s,sp,1024);
}
/*************************************************
************************************************/
void delayms( uchar ticks )
{
uint Count;
uchar Tick;
for (Tick=ticks;Tick>0;Tick--)
{
for (Count=0;Count<=500;Count++);
wdgclr=!wdgclr;
}
}
/************************************************************************/
/* PROCEDURE: Erase_One_Sector */
/* */
/* This procedure can be used to erase a total of 4096 bytes. */
/* */
/* Input: */
/* Dst DESTINATION address where the erase operation starts */
/* */
/* Output: */
/* NONE */
/************************************************************************/
void Erase_One_Sector (uint Sec)
{
// uchar xdata *Temp;
//Temp=0x0000;
FPGH=(page/256)&0x06;FPGL=5;
XBYTE[0x8555]=0Xaa;
FPGL=2;
XBYTE[0x8aaa]=0x55;
FPGL=5;
XBYTE[0x8555]=0X80;
FPGL=5;
XBYTE[0x8555]=0Xaa;
FPGL=2;
XBYTE[0x8aaa]=0X55;
FPGH=Sec/256;FPGL=Sec%256;
XBYTE[0x8000]=0x30;
delayms(25); /* Delay time = Tse */
}
/************************************************************************/
/* PROCEDURE: Check_Toggle_Ready */
/* */
/* During the internal program cycle, any consecutive read operation */
/* on DQ6 will produce alternating 0's and 1's (i.e. toggling between */
/* 0 and 1). When the program cycle is completed, DQ6 of the data will */
/* stop toggling. After the DQ6 data bit stops toggling, the device is */
/* ready for next operation. */
/* */
/* Input: */
/* Dst Must already be set-up by the caller */
/* */
/* Output: */
/* None */
/************************************************************************/
void Check_Toggle_Ready (uchar xdata *Dst)
{
uchar Loop = TRUE;
uchar PreData;
uchar CurrData;
unsigned int TimeOut = 0;
PreData = *Dst;
PreData = PreData & 0x40;
while ((TimeOut< 0xFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x40;
if (PreData == CurrData)
Loop = FALSE; /* ready to exit the while loop */
PreData = CurrData;
TimeOut++;
wdgclr=!wdgclr;
}
}
/************************************************************************/
/* PROCEDURE: Program_One_Byte */
/* */
/* This procedure can be used to program ONE byte of data to the */
/* 39VF016. */
/* */
/* NOTE: It is necessary to first erase the sector containing the */
/* byte to be programmed. */
/* */
/* Input: */
/* Src The BYTE which will be written to the 39VF016 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Byte (uchar Src, uchar xdata *Dst)
{
// uchar xdata *Temp;
uchar xdata *DestBuf;
wdgclr=!wdgclr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -