I am a hardware engineer who has managed to cobble together some test
code
for this HCS12 project (dp256) basically I have set up a RS232 link back to
windows terminal. I am testing some inputs (SPI bus) and Digital Outputs,
printing some blurb onto the screen when each channel is switched on
(keyboard hex input), I have some status feedback from the digital Outputs
feeding directly into hardwire Digital Inputs, do some comparison testing
and print out more blurb.
Two things I would like help with:
i. Ideas to tidy it up a bit, my C is not to good, would love to see it done
properly!
ii. Addtional functionality, there is an off chip SPI bus, 12 bit ADC
chip(8AI). I would like to read a channel and pump the data out to the RS232
Terminal. Control characters (like the digitals) are to be read from the
keyboard example type Gx where x is the requested channel number. I
understand the method it is just the C code. This will use an unused SPI bus
(1)
Method:
a. Read input command via 232 from keyboard entry ( using existing
proceedure below but with "Gx" additional commands)
b. Enable the digital switch that selects the ADC chip. Set port H bit 3 to
'1'
c. Enable the appropriate channel.Set ports A0,A1 & A2 to 1.
di.Start D to A conversion process. Set Port A bit 7 to '1'.
dii. Wait one SPI clock pulse for acquisition to take place.
diii. Set A to D conversion to hold. Set port A bit 7 to '0'
div. Wait 14 SPI clock pulses until conversion complete (and transfered onto
SPI bus).
e. Read the SPI, and save the data (configure this bus SPI1 same as SPI0
(digital inputs).
f. Disable the digital switch that selects the analogue channel. Set Port H
bit 3 to '0'.
g. Report the SPI data to RS232 output (using existing proceedure).
This is the code thus far::
/***************************************************************************
***/
/*
*/
/*
*/
/* Project : L019 Power Control Unit
*/
/* File Name : L0199040.c.c
*/
/* Author : Toby Merridan
*/
/* Created : January 2003
*/
/* Description : Hardware Test code entry point main()
*/
/***************************************************************************
***/
#include <hidef.h>
#include <stdio.h>
#include "L0199018.h"
/*Global variables*/
#include <6812DP256.H>
/*CPU Register Definitions*/
#include "L0199006.H"
/*Serial Comms definitions*/
#include "L0199041.h"
/*CPU I/O definitions*/
#include "L0199014.h"
/*Digital IO definitions*/
/* Import from L0199041 */
extern void InitialiseCPU(void);
/* Import from L0199003 */
extern void PerformRealTimeRoutine(void);
#pragma CODE_SEG CodeForcedToPPage33
/***************************************************************************
**/
/* Title : main()
*/
/* Author :
*/
/* Created : November 2002
*/
/* Description : Main program loop
*/
/* Parameters : None
*/
/***************************************************************************
**/
int tt = 0;
void PrintStr(int port, char *str)
{
uint I;
while (*str != 0)
{
SerialPutChar(port,*str);
str++;
I++;
}
}
ulong StrToUlong(char *cmd_str)
{
uint I;
uint J;
ulong ret;
I = 0;
ret = 0;
while ((*cmd_str != 0)&&(I<6))
{
if(*cmd_str <= '9')
{
J = *cmd_str;
J = J - '0';
}
else if (*cmd_str <= 'F')
{
J = *cmd_str;
J = J - 'A';
J = J + 0x0a;
}
else
{
J = *cmd_str;
J = J - 'f';
J = J + 0x0a;
}
ret = ret * 0x10 + J;
cmd_str++;
I++;
}
return ret;
}
void main(void)
{
int count=0;
char cmd_str[20];
char opstr[20];
char *end;
unsigned long int cmd;
int ch;
int serial_port =1;
int dummy;
long int digital;
long int digital_old;
int Chip1Hi,Chip2Hi,Chip1Lo,Chip2Lo;
char str[80];
InitialiseCPU();
dummy= SerialInit(serial_port,RS232,BAUD_9600,NONE,8);
InitDigitalIP(); /*initialise Digital
IP chips*/
while (TRUE)
{
if(count == 0)
{
dummy = ReadDigital(&digital);
if (digital != digital_old)
{
digital_old = digital;
Chip2Lo = digital & 0xFF;
Chip2Hi = digital >> 8 & 0xFF;
Chip1Lo = digital >> 16 & 0xFF;
Chip1Hi = digital >> 24 & 0xFF;
sprintf( str,"Digital I/P Reads =\r\n ");
PrintStr(serial_port, str);
sprintf( str,"chip1Hi = %x Chip1Lo = %x Chip2Hi = %x Chip2Lo =
%x\r\n\n",Chip1Hi,Chip1Lo,Chip2Hi,Chip2Lo);
PrintStr(serial_port, str);
sprintf( str,"Status I/P Reads = \r\n");
PrintStr(serial_port, str);
sprintf( str,"Ch0= %x Ch1= %x Ch2/3= %x Ch4/5= %x Ch6= %x Ch7= %x
Ch8= %x\r\n",STATUS_CHAN_0, STATUS_CHAN_1,STATUS_CHAN_2_3,
STATUS_CHAN_4_5,STATUS_CHAN_6,STATUS_CHAN_7,STATUS_CHAN_8);
PrintStr(serial_port, str);
sprintf( str,"Ch9= %x Ch10 %x Ch11= %x Ch12= %x Ch13= %x Ch14= %x
Ch15= %x\r\n\n\n",STATUS_CHAN_9,STATUS_CHAN_10,STATUS_CHAN_11,
STATUS_CHAN_12,STATUS_CHAN_13,STATUS_CHAN_14,STATUS_CHAN_15);
PrintStr(serial_port, str);
}
}
cmd_str[6]='\n';
ch= SerialGetChar(serial_port);
if (((ch >= '0') && (ch <= '9')) || ((ch >=
'A') && (ch <= 'F')) || ((ch
>= 'a') && (ch <=
'f')))
{
dummy= SerialPutChar(serial_port,ch);
switch(count)
{
case 0:
case 1:
case 2:
case 3:
case 4:
cmd_str[count]= ch;
count ++;
break;
case 5:
default:
cmd_str[5]= ch;
count = 0;
dummy = SerialPutChar(serial_port,'\n');
dummy = SerialPutChar(serial_port,'\r');
cmd = StrToUlong(cmd_str);
/******* INPUT DEMAND and OUTPUT COMMAND Output Channel
0******************************************************/
if (cmd & 0x01) // Input
Switch State test
{
DIGITAL_OUT_0 = 1; // Switch on
DO0 if true
sprintf( str, "Dig Out Ch0 ON\r\n");
PrintStr(serial_port, str);
}
else
{
DIGITAL_OUT_0 = 0; // Switch
off D00 if false
sprintf( str, "Dig Out Ch0 OFF\r\n");
PrintStr(serial_port, str);
}
if (cmd & 0x02)
{
DIGITAL_OUT_1 = 1;
sprintf( str, "Dig Out Ch1 ON\r\n");
PrintStr(serial_port, str);
}
else
{
DIGITAL_OUT_1 = 0;
}
if (cmd & 0x04)
{
DIGITAL_OUT_2 = 1;
}
else
{
DIGITAL_OUT_2 = 0;
}
if (cmd & 0x08)
{
DIGITAL_OUT_3 = 1;
}
else
{
DIGITAL_OUT_3 = 0;
}
if (cmd & 0x10)
{
DIGITAL_OUT_4 = 1;
}
else
{
DIGITAL_OUT_4 = 0;
}
if (cmd & 0x20)
{
DIGITAL_OUT_5 = 1;
}
else
{
DIGITAL_OUT_5 = 0;
}
if (cmd & 0x40)
{
DIGITAL_OUT_6 = 1;
}
else
{
DIGITAL_OUT_6 = 0;
}
if (cmd & 0x80)
{
DIGITAL_OUT_7 = 1;
}
else
{
DIGITAL_OUT_7 = 0;
}
if (cmd & 0x0100)
{
DIGITAL_OUT_8 = 1;
}
else
{
DIGITAL_OUT_8 = 0;
}
if (cmd & 0x0200)
{
DIGITAL_OUT_9 = 1;
}
else
{
DIGITAL_OUT_9 = 0;
}
if (cmd & 0x0400)
{
DIGITAL_OUT_10 = 1;
}
else
{
DIGITAL_OUT_10 = 0;
}
if (cmd & 0x0800)
{
DIGITAL_OUT_11 = 1;
}
else
{
DIGITAL_OUT_11 = 0;
}
if (cmd & 0x1000)
{
DIGITAL_OUT_12 = 1;
}
else
{
DIGITAL_OUT_12 = 0;
}
if (cmd & 0x2000)
{
DIGITAL_OUT_13 = 1;
}
else
{
DIGITAL_OUT_13 = 0;
}
if (cmd & 0x4000)
{
DIGITAL_OUT_14 = 1;
}
else
{
DIGITAL_OUT_14 = 0;
}
if (cmd & 0x8000)
{
DIGITAL_OUT_15 = 1;
}
else
{
DIGITAL_OUT_15 = 0;
}
if (cmd & 0x010000)
{
PWM_OUT_0 = 1;
}
else
{
PWM_OUT_0 = 0;
}
if (cmd & 0x020000)
{
PWM_OUT_1 = 1;
}
else
{
PWM_OUT_1 = 0;
}
if (cmd & 0x040000)
{
PWM_OUT_2 = 1;
}
else
{
PWM_OUT_2 = 0;
}
if (cmd & 0x080000)
{
PWM_OUT_3 = 1;
}
else
{
PWM_OUT_3 = 0;
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 0 ****************************************/
if (DIGITAL_OUT_0 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_0 ==1)
{
sprintf( str, "Dig Out Ch0 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_0 == 0)
{
if (STATUS_CHAN_0 ==0)
{
sprintf( str, "Dig Out Ch0 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_0 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_0 ==1)
{
sprintf( str, "Dig Out Ch0 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_0 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_0 ==0)
{
sprintf( str, "Dig Out Ch0 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 1 ****************************************/
if (DIGITAL_OUT_1 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_1 ==1)
{
sprintf( str, "Dig Out Ch1 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_1 == 0)
{
if (STATUS_CHAN_1 ==0)
{
sprintf( str, "Dig Out Ch1 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_1 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_1 ==1)
{
sprintf( str, "Dig Out Ch1 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_1 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_1 ==0)
{
sprintf( str, "Dig Out Ch1 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 2 & 3 ****************************************/
if (DIGITAL_OUT_2 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==1)
{
if (STATUS_CHAN_2_3 ==1)
{
sprintf( str, "Dig Out Ch2/3 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==0)
{
if (STATUS_CHAN_2_3 ==0)
{
sprintf( str, "Dig Out Ch2/3 Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==0)
{
if (STATUS_CHAN_2_3 ==1)
{
sprintf( str, "Dig Out Ch2/3 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==1)
{
if (STATUS_CHAN_2_3 ==0)
{
sprintf( str, "Dig Out Ch3 Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==1)
{
if (STATUS_CHAN_2_3 ==1)
{
sprintf( str, "Dig Out Ch2/3 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==0)
{
if (STATUS_CHAN_2_3 ==0)
{
sprintf( str, "Dig Out Ch2 Open Load\r\n");
// Send out Open Load message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==0)
{
if (STATUS_CHAN_2_3 ==1)
{
sprintf( str, "Dig Out Ch2/3 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_2 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_3 ==1)
{
if (STATUS_CHAN_2_3 ==0)
{
sprintf( str, "Dig Out Ch2/3 at least one output Open
Load\r\n"); // Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 4 & 5 ****************************************/
if (DIGITAL_OUT_4 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==1)
{
if (STATUS_CHAN_4_5 ==1)
{
sprintf( str, "Dig Out Ch4/5 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==0)
{
if (STATUS_CHAN_4_5 ==0)
{
sprintf( str, "Dig Out Ch4/5 Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==0)
{
if (STATUS_CHAN_4_5 ==1)
{
sprintf( str, "Dig Out Ch4/5 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==1)
{
if (STATUS_CHAN_4_5 ==0)
{
sprintf( str, "Dig Out Ch5 Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==1)
{
if (STATUS_CHAN_4_5 ==1)
{
sprintf( str, "Dig Out Ch4/5 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==0)
{
if (STATUS_CHAN_4_5 ==0)
{
sprintf( str, "Dig Out Ch4 Open Load\r\n");
// Send out Open Load message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==0)
{
if (STATUS_CHAN_4_5 ==1)
{
sprintf( str, "Dig Out Ch4/5 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
}
if (DIGITAL_OUT_4 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (DIGITAL_OUT_5 ==1)
{
if (STATUS_CHAN_4_5 ==0)
{
sprintf( str, "Dig Out Ch4/5 at least one output Open
Load\r\n"); // Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 6 ****************************************/
if (DIGITAL_OUT_6 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_6 ==1)
{
sprintf( str, "Dig Out Ch6 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_6 == 0)
{
if (STATUS_CHAN_6 ==0)
{
sprintf( str, "Dig Out Ch6 Opoen Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_6 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_6 ==1)
{
sprintf( str, "Dig Out Ch6 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_6 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_6 ==0)
{
sprintf( str, "Dig Out Ch6 Overheat Detected\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 7 ****************************************/
if (DIGITAL_OUT_7 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_7 ==1)
{
sprintf( str, "Dig Out Ch7 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_7 == 0)
{
if (STATUS_CHAN_7 ==0)
{
sprintf( str, "Dig Out Ch7 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_7 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_7 ==1)
{
sprintf( str, "Dig Out Ch7 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_7 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_7 ==0)
{
sprintf( str, "Dig Out Ch7 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 8 ****************************************/
if (DIGITAL_OUT_8 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_8 ==1)
{
sprintf( str, "Dig Out Ch8 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_8 == 0)
{
if (STATUS_CHAN_8 ==0)
{
sprintf( str, "Dig Out Ch8 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_8 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_8 ==1)
{
sprintf( str, "Dig Out Ch8 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_8 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_8 ==0)
{
sprintf( str, "Dig Out Ch8 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 9 ****************************************/
if (DIGITAL_OUT_9 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_9 ==1)
{
sprintf( str, "Dig Out Ch9 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_9 == 0)
{
if (STATUS_CHAN_9 ==0)
{
sprintf( str, "Dig Out Ch9 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_9 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_9 ==1)
{
sprintf( str, "Dig Out Ch9 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_9 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_9 ==0)
{
sprintf( str, "Dig Out Ch9 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 10 ****************************************/
if (DIGITAL_OUT_10 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_10 ==1)
{
sprintf( str, "Dig Out Ch10 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_10 == 0)
{
if (STATUS_CHAN_10 ==0)
{
sprintf( str, "Dig Out Ch10 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_10 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_10 ==1)
{
sprintf( str, "Dig Out Ch10 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_10 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_10 ==0)
{
sprintf( str, "Dig Out Ch10 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 11 ****************************************/
if (DIGITAL_OUT_11 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_11 ==1)
{
sprintf( str, "Dig Out Ch11 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_11 == 0)
{
if (STATUS_CHAN_11 ==0)
{
sprintf( str, "Dig Out Ch11 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_11 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_11 ==1)
{
sprintf( str, "Dig Out Ch11 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_11 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_11 ==0)
{
sprintf( str, "Dig Out Ch11 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 12 ****************************************/
if (DIGITAL_OUT_12 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_12 ==1)
{
sprintf( str, "Dig Out Ch12 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_12 == 0)
{
if (STATUS_CHAN_12 ==0)
{
sprintf( str, "Dig Out Ch12 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_12 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_12 ==1)
{
sprintf( str, "Dig Out Ch12 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_12 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_12 ==0)
{
sprintf( str, "Dig Out Ch12 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 13 ****************************************/
if (DIGITAL_OUT_13 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_13 ==1)
{
sprintf( str, "Dig Out Ch13 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_13 == 0)
{
if (STATUS_CHAN_13 ==0)
{
sprintf( str, "Dig Out Ch13 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_13 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_13 ==1)
{
sprintf( str, "Dig Out Ch13 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_13 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_13 ==0)
{
sprintf( str, "Dig Out Ch13 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 14 ****************************************/
if (DIGITAL_OUT_14 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_14 ==1)
{
sprintf( str, "Dig Out Ch14 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_14 == 0)
{
if (STATUS_CHAN_14 ==0)
{
sprintf( str, "Dig Out Ch14 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_14 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_14 ==1)
{
sprintf( str, "Dig Out Ch14 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_14 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_14 ==0)
{
sprintf( str, "Dig Out Ch14 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
/*********TEST FOR OVERLOAD & SWITCH FAILURE CONDITIONS Output
Channel 15****************************************/
if (DIGITAL_OUT_15 == 1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_15 ==1)
{
sprintf( str, "Dig Out Ch15 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_15 == 0)
{
if (STATUS_CHAN_15 ==0)
{
sprintf( str, "Dig Out Ch15 Overheat or Switch Failure\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_15 == 0)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_15 ==1)
{
sprintf( str, "Dig Out Ch15 O.K\r\n");
// Send out O.K message to RS232 port
PrintStr(serial_port, str);
}
}
if (DIGITAL_OUT_15 ==1)
// Compare Digital Output State with Digital Output Feedfeedback input
{
if (STATUS_CHAN_15 ==0)
{
sprintf( str, "Dig Out Ch15 Overheat or Open Load\r\n");
// Send out Fault message to RS232 port
PrintStr(serial_port, str);
}
}
//end case
}
}
}
}
Port definitions etc:
/***************************************************************************
***/
/* /*
*/
/* Project : L019 Power Control Unit
*/
/* File Name : L0199004.h
*/
/* Author :
*/
/* Created : 12th November 2002
*/
/* Description : CPU core Hardwre definitions
*/
/***************************************************************************
***/
/***************************************************************************
***/
/* CPU Hardware definitions
*/
/***************************************************************************
***/
#ifdef PCU
/*Hardware Consts for PCU hardware*/
#define OSC_CLK 10000000
/*Oscillator clock 10MHz*/
#define SYS_CLK 10000000
/*System Clock 50MHz*/
#define BUS_CLK 5000000
// #define OSC_CLK 16000000
/*Oscillator clock 16MHz*/
// #define SYS_CLK 16000000
/*System Clock 16MHz*/
// #define BUS_CLK 8000000
/*Bus clock 8MHz*/
/*Bus clock 25MHz*/
#else
/*************************Hardware Consts for Evaluation
Board*****************/
#define OSC_CLK 16000000
/*Oscillator clock 16MHz*/
#define SYS_CLK 16000000
/*System Clock 16MHz*/
#define BUS_CLK 8000000
/*Bus clock 8MHz*/
#endif
/***********************CPU I/O switch output pin
definitions******************/
#pragma MESSAGE DISABLE C1106
/*Non-standard bitfield type */
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_A @0x00;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_B @0x01;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_J @0x268;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_K @0x32;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_M @0x250;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_P @0x258;
extern volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_T @0x240;
#pragma MESSAGE WARNING C1106
/*Non-standard bitfield type */
#define DIG_IP_CS CPU_PORT_B.bit7
#define DIGITAL_OUT_0 CPU_PORT_T.bit7
#define DIGITAL_OUT_1 CPU_PORT_B.bit1
#define DIGITAL_OUT_2 CPU_PORT_J.bit0
#define DIGITAL_OUT_3 CPU_PORT_T.bit4
#define DIGITAL_OUT_4 CPU_PORT_J.bit1
#define DIGITAL_OUT_5 CPU_PORT_T.bit2
#define DIGITAL_OUT_6 CPU_PORT_P.bit5
#define DIGITAL_OUT_7 CPU_PORT_P.bit7
#define DIGITAL_OUT_8 CPU_PORT_K.bit3
#define DIGITAL_OUT_9 CPU_PORT_P.bit4
#define DIGITAL_OUT_10 CPU_PORT_P.bit6
#define DIGITAL_OUT_11 CPU_PORT_K.bit7
#define DIGITAL_OUT_12 CPU_PORT_M.bit0
#define DIGITAL_OUT_13 CPU_PORT_K.bit0
#define DIGITAL_OUT_14 CPU_PORT_K.bit2
#define DIGITAL_OUT_15 CPU_PORT_K.bit1
#define PWM_OUT_0 CPU_PORT_P.bit2
#define PWM_OUT_1 CPU_PORT_P.bit3
#define PWM_OUT_2 CPU_PORT_P.bit0
#define PWM_OUT_3 CPU_PORT_P.bit1
#define STATUS_CHAN_0 CPU_PORT_B.bit0
#define STATUS_CHAN_1 CPU_PORT_T.bit6
#define STATUS_CHAN_2_3 CPU_PORT_T.bit5
#define STATUS_CHAN_4_5 CPU_PORT_T.bit3
#define STATUS_CHAN_6 CPU_PORT_K.bit5
#define STATUS_CHAN_7 CPU_PORT_A.bit6
#define STATUS_CHAN_8 CPU_PORT_B.bit3
#define STATUS_CHAN_9 CPU_PORT_K.bit4
#define STATUS_CHAN_10 CPU_PORT_A.bit2
#define STATUS_CHAN_11 CPU_PORT_A.bit1
#define STATUS_CHAN_12 CPU_PORT_A.bit5
#define STATUS_CHAN_13 CPU_PORT_B.bit5
#define STATUS_CHAN_14 CPU_PORT_B.bit4
#define STATUS_CHAN_15 CPU_PORT_B.bit6
/***************************************************************************
**/
/*
*/
/*
*/
/* Project : L019 Power Control Unit
*/
/* File Name : L0199004.c
*/
/* Author : James Hudson
*/
/* Created : 7th November 2002
*/
/* Description : CPU core Hardwre Access Code
*/
/***************************************************************************
**/
/***************************************************************************
**/
/* CPU Register definitions
*/
/***************************************************************************
**/
#define __DECL__6812DP256_H__
/*make this include the definitions */
#include <6812dp256.h>
#include <hidef.h>
/*machine dependent stuff*/
/***************************************************************************
***/
/* FLASH Protection block declaration
*/
/***************************************************************************
***/
typedef unsigned char tUINT8;
typedef unsigned short tUINT16;
typedef struct
{
const tUINT16 key1;
const tUINT16 key2;
const tUINT16 key3;
const tUINT16 key4;
const tUINT16 res1;
const tUINT8 prot3;
const tUINT8 prot2;
const tUINT8 prot1;
const tUINT8 prot0;
const tUINT8 res2;
const tUINT8 security;
}tFlashProt;
#pragma CONST_SEG FLASH_PROT
extern const tFlashProt FlashProtection =
{
0xFFFF,
/* key1 */
0xFFFF,
/* key2 */
0xFFFF,
/* key3 */
0xFFFF,
/* key4 */
0xFFFF,
/* res1 */
0xFF,
/* block 3 protection */
0xFF,
/* block 2 protection */
0xFF,
/* block 1 protection */
0xFF,
/* block 0 protection */
0xFF,
/* res2 */
0xFE,
/* security: unsecured */
};
#pragma CONST_SEG DEFAULT
/***************************************************************************
***/
#pragma CODE_SEG DEFAULT
/***************************************************************************
***/
/* Title : InitialiseCPU()
*/
/* Author :
/* Created :
*/
/* Description : Initialises core CPU registers
*/
/* Parameters : None
*/
/***************************************************************************
***/
/**********************CPU I/O switch output pin
definitions*******************/
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_A @0x00;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_B @0x01;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_J @0x268;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_K @0x32;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_M @0x250;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_P @0x258;
volatile struct
{
uchar bit0:1;
uchar bit1:1;
uchar bit2:1;
uchar bit3:1;
uchar bit4:1;
uchar bit5:1;
uchar bit6:1;
uchar bit7:1;
}CPU_PORT_T @0x240;
volatile unsigned char MODRR @0x0257;
/*Module routing register*/
#ifdef PCU
/*Code version for PCU hardware*/
void InitialiseCPU(void)
{
IRQEN = 0;
/* disable IRQ*/
MODRR = 0x40;
/* redirect SPI2 port to port H pinout*/
//DDRA = 0x81;
DDRB = 0x82;
/* Port B Direction*/
DDRH = 0x88;
DDRJ = 0x03;
/* Port J Direction*/
DDRK = 0x8f;
/* Port K Direction*/
DDRM = 0x01;
/* Port M Direction*/
DDRP = 0xff;
/* Port P Direction*/
DDRT = 0x94;
/* Port T Direction*/
PORTB = 0x80;
/* Port B OPs off*/
PTJ = 0x00;
/* Port J OPs off*/
PORTK = 0x00;
/* Port K OPs off*/
PTM = 0x00;
/* Port M OPs off*/
PTP = 0x00;
/* Port P OPs off*/
PTT = 0x00;
/* Port T OPs off*/
RTICTL = 0x4b;
/* pre scaler 100 Hz for 10MHz xtal*/
CRGINT = 0x80;
/* enable RTI*/
EnableInterrupts;
}
#else
/*Code version for Evaluation Board*/
void InitialiseCPU(void)
{
IRQEN = 0;
/* disable IRQ*/
DDRB = 0xff;
/* Port B output*/
// RTICTL = 0x7f;
/* pre scaler*/
// CRGINT = 0x80;
/* enabkle RTI*/
EnableInterrupts;
}
#endif
Thanks for you help
Toby Merridan
|