How to use PIC microcontroller to expand 8255A parallel port

Publisher:Meiren520Latest update time:2020-01-12 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

__CONFIG(0x3B31);

#defineA0RB0

#defineA1RB1

#defineCSRB2

#defineLERD0

#defineWRRD6

#defineRDRD7

How to use PIC microcontroller to expand 8255A parallel port
 

const unsigned chartab[]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e, 0xff}; //0-F-all off-common anode digital tube

unsignedchartmp[]={0,0,0,0,0,0,0,0};

voiddelay1ms(unsignedintx)

{

unsignedchari;

for(;x》0;x--)

for(i=0;i《165;i++);

}

voidins()

{

TRISB=0x00;

PORTB=0x00;

TRISD=0x00;

PORTD=0x00;

LE=0;WR=1;RD=1;//Turn off 373, prohibit 8255 reading and writing

}

voidinit_8255()

{

LE=1;A1=1;A0=1;CS=0;//Open 373, send write controller command, CS chip select is allowed

LE=0; //Lock 373, keep A1.A0, CS

PORTB=0x80; //Send control command

WR=0; //Open write 8255 signal

NOP();NOP();

}

voidwrite_data(unsignedcharcomm,unsignedchardata)//comm:0=A,1=B,2=C

{

if(comm==0)

{

WR=1;

LE=1;A1=0;A0=0;CS=0;

LE=0;

PORTB=data;

WR=0;

NOP();NOP();

}

if(comm==1)

{

WR=1;

LE=1;A1=0;A0=1;CS=0;

LE=0;

PORTB=data;

WR=0;

NOP();NOP();

}

if(comm==2)

{

WR=1;

LE=1;A1=1;A0=0;CS=0;

LE=0;

PORTB=data;

WR=0;

NOP();NOP();

}

}

voiddisplay()

{

unsignedchari,LED;

LED=0x01;

for(i=0;i《8;i++)

{

write_data(0,tab[tmp[i]]);

write_data(1,LED);

LED《《=1;

delay1ms(2);

write_data(1,0x00);

}

}

i ca n't

{

unsignedchari,j,RR[24];

heat();

init_8255();

while(1)

{

for (i = 0; i < 24; i ++) // All values ​​are assigned to 16, which means they are displayed as empty. This can be simplified, but it doesn't matter for demonstration purposes.

RR[i]=16;

RR[8]=2;RR[9]=0;RR[10]=0;RR[11]=9;RR[12]=0;RR[13]=7;RR[14]=1;RR[15]=2;

for(j=0;j《16;j++)

{

for (i=0;i<8;i++) // assign RR[16] to tmp[]

tmp[i]=RR[16+i];

for(i=0;i《23;i++)

display();

for(i=23;i》0;i--)//Here, shift RR[] right by one bit in the array

RR[i+1]=RR[i];

}

}

}


Reference address:How to use PIC microcontroller to expand 8255A parallel port

Previous article:Temperature measurement program sharing based on PIC microcontroller
Next article:Design of dynamic scanning display of digital tube by PIC single chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号