/******************************************************************
程序名:host
功能:测量电流,并发数据发送给LED595程序,接受用户键盘输入跟设置。
创建时间:2004-3-30
作者:
******************************************************************/
#include <reg52.h>
#include <intrins.h>
#include "host.h"
#include "SEGCODE.h"
#define SIZE_OF_KEYBD_MENU 30 //菜单长度
//#define nop2() _nop_();_nop_();
KbdTabStruct code KeyTab[SIZE_OF_KEYBD_MENU] =
{
{0, 0, 0, 0, 1, (*OptionProg)},
{1, 5, 2, 0, 6, (*OptionAYS)},
{2, 1, 3, 0, 7, (*OptionIn_Out)},
{3, 2, 4, 0, 9, (*OptionALR)},
{4, 3, 5, 0, 11, (*OptionSecr)},
{5, 4, 1, 0, 12, (*OptionAdBd)},
{6, 6, 6, 1, 1, (*AutoZero)},
{7, 8, 8, 2, 14, (*InputX)},
{8, 7, 7, 2, 15, (*OutputX)},
{9, 10, 10, 3, 3, (*ALROFF)},
{10, 9, 9, 3, 16, (*ALRON)},
{11,11, 11, 4, 4, (*Passward)},
{12,13, 13, 5, 18, (*AddrX)},
{13,12, 12, 5, 19, (*BaudX)},
{14,14, 14, 7, 20, (*Inp)},
{15,15, 15, 8, 21, (*Oup)},
{16,17, 17, 10, 22, (*ALRLX)},
{17,16, 16, 10, 23, (*ALRHX)},
{18,18, 18, 12, 24, (*Address)},
{19,19, 19, 13, 25, (*Baud)},
{20,20, 20, 14, 7, (*SetInput)},
{21,21, 21, 15, 26, (*SetOutput)},
{22,22, 22, 16, 27, (*AL_L)},
{23,23, 23, 17, 28, (*AL_H)},
{24,24, 24, 18, 19, (*SetAddress)},
{25,25, 25, 19, 18, (*SetBaud)},
{26,26, 26, 21, 29, (*Point)},
{27,27, 27, 22, 23, (*SetAL_L)},
{28,28, 28, 23, 22, (*SetAL_H)},
{29,29, 29, 26, 8, (*SetPoint)}
};
/*25045操作子程序集*/
/*;*******************************************************************************************
*
;* Name: WREN_CMD
;* Description: Set write enable latch
;* Function: This routine sends the command to enable writes to the EEPROM memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************************
*/
/*写使能子程序*/
void wren_cmd(void)
{
uchar aa;
SCK=0;/* Bring SCK low */
CS=0;/* Bring /CS low */
aa=WREN_INST;
outbyt(aa);/* Send WREN instruction */
SCK=0;/* Bring SCK low */
CS=1;/* Bring /CS high */
}
/*;*******************************************************************************************
*
;* Name: WRDI_CMD
;* Description: Reset write enable latch
;* Function: This routine sends the command to disable writes to the EEPROM memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************************
*/
/*写使能复位子程序*/
//void wrdi_cmd(void)
//{
// uchar aa;
// SCK=0;/* Bring SCK low */
// CS=0;/* Bring /CS low */
// aa=WRDI_INST;
// outbyt(aa);/* Send WRDI instruction */
// SCK=0;/* Bring SCK low */
// CS=1;/* Bring /CS high */
//}
/*;*******************************************************************************************
*
;* Name: WRSR_CMD
;* Description: Write Status Register
;* Function: This routine sends the command to write the WD0, WD1, BP0 and BP0 EEPROM
;* bits in the status register
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************************
*/
/*写状态寄存器子程序*/
void wrsr_cmd(void)
{
uchar aa;
SCK=0;/* Bring SCK low */
CS=0;/* Bring /CS low */
aa=WRSR_INST;
outbyt(aa) ;/* Send WRSR instruction */
aa=STATUS_REG;
outbyt(aa);/* Send status register */
SCK=0;/* Bring SCK low */
CS=1;/* Bring /CS high */
wip_poll();/* Poll for completion of write cycle */
}
/*;*******************************************************************************************
*
;* Name: RDSR_CMD
;* Description: Read Status Register
;* Function: This routine sends the command to read the status register
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = status registerXicor Application Note AN21
;* Register Usage: A
;*******************************************************************************************
*/
/*读状态寄存器,读出的数据放入到aa中*/
uchar rdsr_cmd (void)
{
uchar aa;
SCK=0;
CS=0;
aa=RDSR_INST;
outbyt(aa);
aa=inputbyt();
SCK=0;
CS=1;
return aa;
}
/*;*******************************************************************************************
*
;* Name: BYTE_WRITE
;* Description: Single Byte Write
;* Function: This routine sends the command to write a single byte to the EEPROM memory
array
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;*******************************************************************************************
*/
/*字节写入,aa为写入的数据,dd为写入的地址,对于25045而言为000-1FF*/
void byte_write(aa,dd)
uchar aa;
uint dd;
{
SCK=0;
CS=0;
outbyt((uchar)(dd>255?(0x08|WRITE_INST):WRITE_INST));
//outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including MSB of address */
/*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
outbyt((uchar)(dd&0x00ff));
/*输出低位地址到25045*/
outbyt(aa);
/*写入数据到25045的对应单元*/
SCK=0;
CS=1;
wip_poll();
/*检测是否写完*/
}
/*;*******************************************************************************************
*
;* Name: BYTE_READ
;* Description: Single Byte Read
;* Function: This routine sends the command to read a single byte from the EEPROM memory
array
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = read byte
;* Register Usage: A, BXicor Application Note AN21
;*******************************************************************************************
*/
/*字节读出,其中dd为读出的地址,返回的值为读出的数据*/
uchar byte_read(dd)
uint dd;
{
uchar cc;
SCK=0;
CS=0;
outbyt((uchar)(dd>255?(0x08|READ_INST):READ_INST));
//outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);/* Send READ_INST instruction including MSB of address */
/*将高位地址左移3位与读出先导字相或,得到正确的先导字写入25045*/
outbyt((uchar)(dd&0x00ff));
/*输出低位地址到25045*/
cc=inputbyt();/*得到读出的数据*/
SCK=0;
CS=1;
return cc;
}
/*;*******************************************************************************************
*
;* Name: PAGE_WRITE
;* Description: Page Write
;* Function: This routine sends the command to write three consecutive bytes to the EEPROM
;* memory array using page mode
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;*******************************************************************************************
*/
/*页面写入,其中aa1,aa2,aa3,aa4为需要写入的4个数据(最大也就只能一次写入4个字,dd为写入的首地址*/
void page_write(aa1,aa2,aa3,aa4,dd)
uchar aa1,aa2,aa3,aa4;
uint dd;
{
SCK=0;
CS=0;
outbyt((uchar)(dd>255?(0x08|WRITE_INST):WRITE_INST));
//outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including MSB of address */
/*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
outbyt((uchar)(dd&0x00ff));
/*写入低位地址到25045*/
outbyt(aa1);
/*写入数据1到25045的对应单元*/
outbyt(aa2);
/*写入数据2到25045的对应单元*/
outbyt(aa3);
/*写入数据3到25045的对应单元*/
outbyt(aa4);
/*写入数据4到25045的对应单元*/
SCK=0;
CS=1;
wip_poll();
}
/*;*******************************************************************************************
*
;* Name: RST_WDOG
;* Description: Reset Watchdog Timer
;* Function: This routine resets the watchdog timer without sending a command
;* Calls: None
;* Input: None
;* Outputs: None
;* Register Usage: None
;*******************************************************************************************
*/
/*复位DOG*/
void rst_wdog (void)
{
CS=0;
CS=1;
}
/*;*******************************************************************************************
*
;* Name: WIP_POLL
;* Description: W