📄 armacqui_dom12a.c
字号:
//-----------------------------------------------------------------------------
// Project Title : Armature (Resistance) tester for stator.
// Project No. :
// Project Ver. : 1.00
// File Name : ArmAcqui_DOM12A.c
// Revision : 1.00
// Initial Date : 25-Sep.,2003
// Modify Date :
// Description : DOM-12A 3 range of resistance measurement
// derived from DOM-132B
//-----------------------------------------------------------------------------
#include <atmel\at89s53.h>
#include <absacc.h>
#include "AcqUart.h"
#include "Acquisition.h"
#include "ArmAcqui.h"
#include "eep8252.h"
//#define debug
//-----------------------------------------------------------------------------
#define MSB10ms -20000/256
#define LSB10ms -20000%256
#define uchar unsigned char
//-----------------------------------------------------------------------------
#define MAX_COMM_SLOT 24
//-----------------------------------------------------------------------------
#define UART_TEST 0x80
#define UART_CONFIG_SLOT 0x81
#define UART_CONFIG_PGAIN 0x82
#define UART_ROOM_TEMP 0x83
#define UART_R180_TEST 0x84
#define UART_RCOIL_TEST 0x85
#define UART_LCOIL_TEST 0x86
#define UART_COIL_ON 0x87
#define UART_COIL_OFF 0x88
#define UART_EEPR_LSB 0x90
#define UART_EEPR_MSB 0x91
#define UART_EEPROM_R 0x92
#define UART_EEPROM_W 0x93
//-----------------------------------------------------------------------------
#define AD_CH0 0x00
#define AD_CH1 0x40
#define AD_CH2 0x80
#define AD_CH3 0xc0
#define ch0VoltMeas 0x00
// External variables declaration
extern UART_st uart;
extern acquisition_st acqui;
// External func. declaration
extern uchar pgaGAIN_Select(uchar channel, uchar gainorder);
extern void _resistance_measure (void);
extern void _temperature_measure (void);
// Public variables declaration
unsigned tick_clock;
unsigned char arm_slot;
unsigned char ad_ch;
unsigned int eeprom_addr;
unsigned char eeprom_data;
uchar pgaGainCh0Vr;
// newly added variables, def for DOM-12A
// Functions prototype
void _initial_system (void);
void _time_delay (unsigned t);
void _relay_handling (char f, char s);
void _relay_reset (void);
//-----------------------------------------------------------------------------
void main (void)
{
//----------------------------------------------------------
_initial_system();
pgaGainCh0Vr = 0x00; // x1 time
pgaGAIN_Select(ch0VoltMeas, pgaGainCh0Vr);
//----------------------------------------------------------
/*#ifdef debug
uart.cmdIn = 1;
uart.command = UART_ROOM_TEMP;
#endif*/
while (TRUE) {
if (uart.cmdIn) {
switch (uart.command) {
case UART_TEST:
uart.sbuf[0] = 'O';
uart.sbuf[1] = 'K';
uart_reply();
break;
case UART_CONFIG_SLOT :
arm_slot = uart.param;
uart.sbuf[0] = uart.sbuf[1] = 0;
uart_reply();
break;
case UART_CONFIG_PGAIN :
PampGain = uart.param;
uart.sbuf[0] = uart.sbuf[1] = 0;
uart_reply();
break;
case UART_ROOM_TEMP :
_temperature_measure();
uart.sbuf[0] = 25;
uart.sbuf[1] = 0;
uart_reply();
break;
case UART_R180_TEST :
TP2 = SBIT_LOW;
_relay_handling (UART_R180_TEST, uart.param);
TP2 = SBIT_HIGH;
_time_delay(2);
CurSourceOn = SBIT_HIGH;
_time_delay(5); //50ms delay
_resistance_measure();
//_resistance_measure();
CurSourceOn = SBIT_LOW; // off
uart.sbuf[0] = ((unsigned char *)&acqui.resistance)[0];
uart.sbuf[1] = ((unsigned char *)&acqui.resistance)[1];
uart_reply();
break;
case UART_RCOIL_TEST :
_relay_handling (UART_RCOIL_TEST, uart.param);
_time_delay(3);
CurSourceOn = SBIT_HIGH;
_time_delay(5);
_resistance_measure();
//_resistance_measure();
CurSourceOn = SBIT_LOW;
uart.sbuf[0] = ((unsigned char *)&acqui.resistance)[0];
uart.sbuf[1] = ((unsigned char *)&acqui.resistance)[1];
uart_reply();
break;
case UART_LCOIL_TEST :
_relay_handling (UART_LCOIL_TEST, uart.param);
_time_delay(3);
CurSourceOn = SBIT_HIGH;
_time_delay(5);
_resistance_measure();
//_resistance_measure();
CurSourceOn = SBIT_LOW;
uart.sbuf[0] = ((unsigned char *)&acqui.resistance)[0];
uart.sbuf[1] = ((unsigned char *)&acqui.resistance)[1];
uart_reply();
break;
case UART_EEPR_MSB :
eeprom_addr=((unsigned char *)&eeprom_addr)[0];
break;
case UART_EEPR_LSB :
eeprom_addr=((unsigned char *)&eeprom_addr)[1];
break;
case UART_EEPROM_R :
uart.sbuf[0] = 0x00;
uart.sbuf[1] = _read_eep_byte(eeprom_addr);
uart_reply();
break;
case UART_EEPROM_W :
_write_eep_byte(eeprom_addr,uart.sbuf[1]);
break;
} // end switch
} // end if
} // end while (1)
} // end main
//-----------------------------------------------------------------------------
void _initial_system (void)
{
//----------------------------------------------------------
// setup with enable timer 0 interrupt.
//----------------------------------------------------------
TH0 = MSB10ms; // set timer period
TL0 = LSB10ms;
TMOD |= 0x01; // select mode 1
TR0 = 1; // start timer 0
ET0 = 1; // enable timer 0 interrupt
EA = 1; // global interrupt enable
//----------------------------------------------------------
_uart_initial();
//----------------------------------------------------------
CurSourceOn = SBIT_LOW; // Current Source Off
SensRelay = CurrRelay = SBIT_LOW;
RelayClk = SBIT_LOW;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
PampGain = 0x55; // Set x10 gain for all channels.
_relay_reset();
_time_delay(50); /* power on delay for AT89S8252 and AT89S53 */
SPCR |= SPIE_; // SPI interrupt enable.
SPCR |= MSTR_; // set SPI is master mode.
SPCR |= CPOL_; // set SCLK is high when idle.
SPCR |= CPHA_; // set rising edge is MPU latches.
SPCR |= SPR1_; // set SCK bit rate
SPCR |= SPR0_; // set SCK bit rate Fosc divided by 128
//----------------------------------------------------------
}
//-----------------------------------------------------------------------------
void _relay_handling (char f, char s)
{
char i, p, n;
unsigned long PosRelay, NegRelay;
//
switch (f) {
case UART_R180_TEST :
p = MAX_COMM_SLOT- (s+1);
n = (MAX_COMM_SLOT>>1)-(s+1);
break;
case UART_LCOIL_TEST :
p = (MAX_COMM_SLOT-1)-s;
n = ((MAX_COMM_SLOT>>1)-2)-s;
break;
case UART_RCOIL_TEST :
p = (MAX_COMM_SLOT-2)-s;
n = ((MAX_COMM_SLOT>>1)-1)-s;
break;
}
PosRelay = NegRelay = 0x800000;
i = 0;
while (i++ < p)
PosRelay >>= 1;
i = 0;
while (i++ < n)
NegRelay >>= 1;
RelayOE = SBIT_HIGH;
for (i=0; i<24; i++) {
if ((PosRelay & 0x0001) == 1)
{ SensRelay = SBIT_HIGH;
SensRelay = SBIT_HIGH;
}
else
{ SensRelay = SBIT_LOW;
SensRelay = SBIT_LOW;
}
if ((NegRelay & 0x0001) == 1)
{ CurrRelay = SBIT_HIGH;
CurrRelay = SBIT_HIGH;
}
else
{ CurrRelay = SBIT_LOW;
CurrRelay = SBIT_LOW;
}
//
RelayClk = SBIT_HIGH;
PosRelay >>= 1;
NegRelay >>= 1;
SensRelay = CurrRelay = RelayClk = SBIT_LOW;
}
SensRelaySTB = CurrRelaySTB = SBIT_HIGH;
SensRelaySTB = CurrRelaySTB = SBIT_HIGH;
SensRelaySTB = CurrRelaySTB = SBIT_HIGH;
RelayOE = SBIT_LOW;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
}
//---------------------------------------------------------------------------
void _relay_reset (void)
{
char i;
for (i=0; i<24; i++) {
SensRelay = SBIT_LOW;
CurrRelay = SBIT_LOW;
RelayClk = SBIT_HIGH;
SensRelay = CurrRelay = RelayClk = SBIT_LOW;
}
SensRelaySTB = CurrRelaySTB = SBIT_HIGH;
SensRelaySTB = CurrRelaySTB = SBIT_HIGH;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
SensRelaySTB = CurrRelaySTB = SBIT_LOW;
}
//---------------------------------------------------------------------------
void _time_delay (unsigned t)
{
t += tick_clock;
while (tick_clock != t);
}
//-----------------------------------------------------------------------------
// Timer0 (vector 1) Interrupt handler.
//-----------------------------------------------------------------------------
timer0 (void) interrupt 1 using 3
{
TH0 = MSB10ms;
TL0 = LSB10ms;
++tick_clock;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -