发表于:2005-12-23 09:40:00
13楼
找了找,找到你的所谓的PLC原文件了贴出来大家看一看,我也不解释了,你以后再发贴我也不回了,明眼人懂技术的人一看就明白了.
下面这个文件是他的指令定义
/*
*********************************************************************************************************
* uPLC
* Using the Keil uVision2 compiler
*
* File : Program.h
*********************************************************************************************************
*/
#ifndef _PROGRAM_H_
#define _PROGRAM_H_
//////////////////////////////////////////////////////////////
char code Program[]=
{
"@LD 0.00,"
"@LD C0,"
"@OR 0.01,"
"keep 1.00,"
"LD 9.01,"
"OR 1.01,"
"!AND 9.07,"
"OUT 1.01,"
"LD 1.00,"
"!AND 1.01,"
"OR 9.01,"
"!AND 9.02,"
"OUT 9.01,"
"LD 9.01,"
"AND T1,"
"OR 9.02,"
"!AND 9.03,"
"OUT 9.02,"
"LD 9.02,"
"AND T2,"
"OR 9.03,"
"!AND 9.04,"
"OUT 9.03,"
"LD 9.03,"
"AND T3,"
"OR 9.04,"
"!AND 9.05,"
"OUT 9.04,"
"LD 9.04,"
"AND T4,"
"OR 9.05,"
"!AND 9.06,"
"OUT 9.05,"
"LD 9.05,"
"AND T5,"
"OR 9.06,"
"!AND 9.07,"
"OUT 9.06,"
"LD 9.06,"
"AND T6,"
"OUT 9.07,"
"LD 9.01,"
"TIM 1 #50,"
"LD 9.02,"
"TIM 2 #50,"
"LD 9.03,"
"TIM 3 #50,"
"LD 9.04,"
"TIM 4 #50,"
"LD 9.05,"
"TIM 5 #50,"
"LD 9.06,"
"TIM 6 #50,"
"LD 9.01,"
"LD 0.02,"
"CNT 1 #100,"
"ld 9.00,"
"!out 9.00,"
";"
};
#endif //_PROGRAM_H_
库文件的接口头文件
/*
*********************************************************************************************************
* uPLC
* Using the Keil uVision2 compiler
*
* File : uPLC.h
*********************************************************************************************************
*/
#ifndef _uPLC_H_
#define _uPLC_H_
#define uPLC_IR_SIZE 10 /* Size of inter relays */
#define uPLC_HR_SIZE 5 /* Size of Hoding relays */
#define uPLC_SR_SIZE 10 /* Size of Special relays */
#define uPLC_DM_SIZE 10 /* Size of memory */
#define uPLC_TIM_SIZE 10 //maxinum number of Timer
#define uPLC_CNT_SIZE 5 //Maxinum number of counter
///////////////////////////////////////////////////////////////////////////
/*********************************************************************************************************
* uPLC ERROR CODES
*********************************************************************************************************/
#define InsSize 35
#define uPLC_ERR_NO 0
#define uPLC_ERR_TIMEOUT 10
#define uPLC_ERR_COMM 11 //Communication ERR
/////////////////////////////////////////////////////////////////////////
/*********************************************************************************************************
* uPLC FUNCTION PROTOTYPES
*********************************************************************************************************/
void ExecuteLadder(char *p);
void ReflashTIM(void);
void uPLCInit(void);
int * GetIR(void);
int * GetSR(void);
int * GetHR(void);
int * GetDM(void);
void CheckLadder(char *p);
#endif //_uPLC_H_
所谓的PLC例子程序
/*
*********************************************************************************************************
* EXAMPLE1
* Using the Keil uVision2 compiler
* File : EXAMPLE1.C
*********************************************************************************************************
*/
#include "uPLC.h"
#include "EXAMPLE1.h"
#include "REG52.h" //应与所用的CPU相配
#include "Program.h"
//////////////////////////////////////////////////////////////////////////////////
#define OSC_FREQ (12000000UL)
#define OSC_PER_INST (12)
//Preload value for 20 ms delay
#define PERIOD (20) //100 msec
#define PRELOAD020 (65536 - (unsigned int)(OSC_FREQ * PERIOD / (OSC_PER_INST * 1000)))
#define PRELOAD020H (PRELOAD020 / 256)
#define PRELOAD020L (PRELOAD020 % 256)
#define INTR_TIMER_0 1
unsigned int xdata counter;
///////////////////////////////////////////////////////////////////////////////
void Timer0ISR(void) interrupt INTR_TIMER_0
{
//Reload timer0 value
TL0 = PRELOAD020L;
TH0 = PRELOAD020H;
if(counter%5==0) ReflashTIM();
counter++;
}
///////////////////////////////////////////////////////////////////////////////
void main (void)
{
#if CODE_DEBUGGING
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
#endif
Init();
#if CODE_DEBUGGING
CheckLadder(Program);
#endif
while (1)
{
ExecuteLadder(Program);
MappingIO();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Init(void)
{
P0=P1=P2=P3=0xff;
TMOD &= 0xf0; // clear all T0 bits
TMOD |= 0x01; // set T0 as 16-bit timer
//Set timer0 value as (65536 - 20 * 1000) equivalent to 20 ms
TL0 = PRELOAD020L;
TH0 = PRELOAD020H;
ET0 = 1; // enable timer 0 interrupt
TR0 = 1; // start timer 0
EA = 1; // enable interrupt
// AUXR=0; //选择片内XRAM
uPLCInit();
counter=0;
}
////////////////////////////////////////////////////////////////////////////////
void MappingIO(void)
{
unsigned char In;
unsigned int xdata mt;
int *pIR;
pIR=GetIR();
mt=0;
In=~P3;
mt|=In;
*pIR=mt;
mt=*(pIR+9);
P1=~mt;
}
//////////////////////////////////////////////////////////////////////////////////
例子的头文件
/*
*********************************************************************************************************
* EXAMPLE1.h
* Using the Keil uVision2 compiler
*
* File : EXAMPLE1.h
*********************************************************************************************************
*/
#ifndef _EXAMPLE1_H_
#define _EXAMPLE1_H_
////////////////////////////////////////////////////////////////////////////////
#define CODE_DEBUGGING 0 //1->debugging,0->release
//////////////////////////////////////////////////////////////////////////////////
void Init(void);
void MappingIO(void);
#endif //_EXAMPLE1_H_