📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** 大连双马电子有限公司
** 研 发 部
** 研发一部
**
** http://www.smelecom.com/
**
** 文 件 名: Motorola MCU 11series programme for unencrypt read、write and erase
** 编 写 日 期: 2006年7月17日
** 描 述: This programme is used for read and write the Motorola 11series MCU
** 版 本: the first one
** 编 者: 宋晓伟
***********************************************************************************************************/
#include <reg54.h>
//#include <stdio.h>
//#include <absacc.h>
//#include <intrins.h>
#include <series sub.h>
#include <delay subroutine.h>
//#include <tr and re subroutine.h>
#define uchar unsigned char
#define uint unsigned int
sbit CTRLDIR = P3^3;
sbit CTRL = P3^4;
sbit RST=P1^7;
sbit BDM=P1^4;
sbit relaycs = P1 ^ 6;
sbit relaydin = P1 ^ 0;
sbit relaysck = P1 ^ 1;
uchar Instruction[5];
void J_Config(int config_value)
{
uint m;
m=0;
// P4 &= ~(1<<0); //控制J9
delay100ms();delay100ms();
relaysck = 0;
relaycs = 0;
while(m<16)
{
if(config_value & 1)
{
relaydin=1;
}
else
{
relaydin=0;
}
relaysck=1;
relaysck=0;
m=m+1;
config_value = config_value >> 1;
}
relaycs=1; //锁存
delay100ms();delay100ms();
P4 &= ~(1<<0);
// P4 |= (1<<0);
delay100ms();delay100ms();
}
void operation()
{
P4 &= ~(1<<2);
CTRL=0;
delay1ms();
CTRLDIR=0;
delay40ms();
switch(Instruction[0])
{
case 0x88:Read_datas();;break;
case 0x99:Write_datas();break;
case 0x77:Erase_datas();break;
default:output(0x00);break;
}
delay40ms();
P4 |= (1 << 2); //置灭绿灯
P4 &= ~(1 << 1);
delay200ms();
P4 |= (1 << 1); //蜂鸣器
}
void In_instruction()
{
int k1;
for(k1=0;k1<5;k1++)
{
Instruction[k1]=input();
}
}
uchar Pin_detect()
{
uchar result=0;
if(BDM==1)
result|=0x40;
if(RST==1)
result|=0x01;
return(result);
}
void main()
{
uchar pin_result; //define the pin value//
uchar pin_result_fail;
delay100ms();
output(0x55);
delay4ms();
// EA=1;
// ET1=1;
while(1)
{
P4 |= (1 << 2); //置灭绿灯
CTRL=1;
delay1ms();
CTRLDIR=1;
In_instruction();
J_Config(0x300c); //配置所有主机继电器
P4 |= (1 << 3); //重新开始关闭报错灯
pin_result=(Pin_detect()); //get the pin value//
pin_result_fail=pin_result;
pin_result|=0xbe;
if(pin_result==0xff) //0xff,correct,or return the fault number//
{
output(0x55);
output(pin_result);
operation();
}
else
{
output(0xaa);
output(pin_result_fail);
P4 &= ~(1 << 3); //报错点亮红灯+
P4 &= ~(1 << 1);
delay200ms();delay200ms();
P4 |= (1 << 1); //蜂鸣器
delay200ms();delay200ms();
P4 &= ~(1 << 1);
delay200ms();delay200ms();
P4 |= (1 << 1); //蜂鸣器
delay200ms();delay200ms();
P4 &= ~(1 << 1);
delay200ms();delay200ms();
P4 |= (1 << 1); //蜂鸣器
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -