Pcf8591 ADDA chip, 51 single chip microcomputer and a potentiometer are used here. By controlling the potentiometer, PWM wave is generated to control the rotation of the steering gear. And display the angle on the nixie tube.

Circuit diagram

Design of steering gear rotation controlled by 51 single chip microcomputer

Design of steering gear rotation controlled by 51 single chip microcomputer

Design of steering gear rotation controlled by 51 single chip microcomputer

This is a program

/*———————————————–

Name: pcf8591adda conversion of IIC protocol

Content: This program operates DAAD chip through IIC protocol, reads the voltage of potentiometer, outputs analog quantity, indicates with LED brightness gradient, and selects 12Mhz crystal

————————————————*/

#include“reg52.h”

#Include / / contains NOP null instruction functions_ nop_ ();

#Define addwr 0x90 / / write data address

#Define addrd 0x91 / / read data address

sbit Sda=P1^2; // Define bus connection port

sbit Scl=P1^1;

sbit control_ signal=P1^5;

data unsigned int Display[8];// Define the value of temporarily stored nixie tube

unsigned char code Datatab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// Code table of 7 segments with negative code

unsigned int ADtemp; // Define global variables

unsigned int high,low;

static unsigned int count1;

/*————————————————

Delay procedure

————————————————*/

void mDelay(unsigned char j)

{

unsigned int i;

for(;j》0;j–)

{

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

{;}

}

}

/*————————————————

Initialize timer 0

————————————————*/

void Init_ TImer0(void)

{

Tmod “= 0x01; / / timer setting 0.1ms in 11.0592m crystal

TH0=(65536-78)/256;

TL0=(65536-78)%256; // Timing 0.1ms

ET0=1;// Timer interrupt on

EA=1;// Total interrupt

TR0=1; // Start timer 0

}

/*————————————————

Start IIC bus

————————————————*/

void Start(void)

{

Sda=1;

_ nop_ ();

Scl=1;

_ nop_ ();

Sda=0;

_ nop_ ();

Scl=0;

}

/*————————————————

Stop IIC bus

————————————————*/

void Stop(void)

{

Sda=0;

_ nop_ ();

Scl=1;

_ nop_ ();

Sda=1;

_ nop_ ();

Scl=0;

}

/*————————————————

Reply IIC bus

————————————————*/

void Ack(void)

{

Sda=0;

_ nop_ ();

Scl=1;

_ nop_ ();

Scl=0;

_ nop_ ();

}

/*————————————————

Non answering IIC bus

————————————————*/

void NoAck(void)

{

Sda=1;

_ nop_ ();

Scl=1;

_ nop_ ();

Scl=0;

_ nop_ ();

}

/*————————————————

Send a byte

————————————————*/

void Send(unsigned char Data)

{

unsigned char BitCounter=8;

unsigned char temp;

do

{

temp=Data;

Scl=0;

_ nop_ ();

if((temp&0x80)==0x80)

Sda=1;

else

Sda=0;

Scl=1;

temp=Data《《1;

Data=temp;

BitCounter–;

}

while(BitCounter);

Scl=0;

}

/*————————————————

Read in a byte and return

————————————————*/

unsigned char Read(void)

{

unsigned char temp=0;

unsigned char temp1=0;

unsigned char BitCounter=8;

Sda=1;

do

{

Scl=0;

_ nop_ ();

Scl=1;

_ nop_ ();

if(Sda)

temp=temp|0x01;

else

temp=temp&0xfe;

if(BitCounter-1)

{

temp1=temp《《1;

temp=temp1;

}

BitCounter–;

}

while(BitCounter);

return(temp);

}

/*————————————————

Read the value of ad analog-to-digital conversion, and there is a return value

————————————————*/

unsigned int ReadADC(unsigned char Chl)

{

unsigned int Data;

Start(); // Start signal

Send(AddWr);// 0x90

Ack();

Send(0x40|Chl);// Write the selected channel. This program only uses single ended input, and the differential part needs to be added by itself

//The values of Chl are 0, 1, 2 and 3 respectively, representing 1-4 channels respectively

Ack();

Start();

Send(AddRd); // Read in address

Ack();

Data=Read(); // Read data

Scl=0;

NoAck();

Stop();

return Data; // Return value

}

/******************************************************************/

/*Main program*/

/******************************************************************/

void main()

{

Init_ TImer0();

while(1)

{

unsigned int angle;

ADtemp=ReadADC(0); // The value range of adtemp is 0-255 and the timing time range is 0.5-2.5ms

high=65075-7.2*ADtemp; // ( high=65035-7.8*ADtemp;12MHz)(65535-(460+7.2*ADtemp 11.0592MHz)

low=47563+7.2*ADtemp; // ( low=46035+7.8*ADtemp; ) ( 65535-(17972-7.2*ADtemp 11.0592MHz )

angle=ADtemp*0.7;

Display[0]=Datatab[angle/100];// Processing channel 0 voltage display

Display[1]=Datatab[(angle%100)/10];

Display[2]=Datatab[angle%10];

while(1)

{

P0=Display[count1];// For dynamic scanning nixie tube

P2=count1;

mDelay(1);

count1++;

If (COUNT1 = = 3) / / scan 3 nixie tubes

{

count1=0;

break;

}

}

}

}

/******************************************************************/

/*Timer interrupt function

/******************************************************************/

void TIm(void) interrupt 1 using 1

{

staTIc unsigned char count;

if (!count)

{

control_ signal = 1; // Feed high level

TH0=high/256;

TL0=high%256; }

else

{

control_ signal=0 ;

TH0=low/256;

TL0=low%256;

}

count=~count;

}

Leave a Reply

Your email address will not be published. Required fields are marked *