第 12 章 与 PLC 接口的 4 位 LED 数字显示表
12.2 数显表头软件设计思路
12.4 程序清单
#include <pic16F87x.h>
#include "mydefine.h"
#include <pic.h>
static int flag,flag0,flag1,flag3,led_d;
static int data1[5],data2[5];
static int data,data0,data_1,data_2,sdata;
//=====================子程序=========================
//端口初始化子程序
void initport( )
{
PORTA=0;
PORTB=0;
PORTC=0;
PORTD=0;
ADCON1=0x07;
TRISA=0x03; //设 RA0,RA1 为输入
TRISB=0xE8; //设 RB0,RB1,RB2,RB4 为输出
TRISC=0xFF; //设 C 口为输入
TRISD=0; //设 D 口为输出
}
//判断地址是否相同子程序
int adr_jud(int x)
{
int adress,y;
adress=PORTA&0x03;
x&=0x60;
adress=adress<<5;
if (adress==x) y=1;
elsey=0;
CLRWDT();
return(y);
}