一個光電耦合電路替換繼電器的Proteus仿真
利用光電耦合電路實現低壓控制高壓
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
QQ截圖20190609150828.png (89.47 KB, 下載次數: 56)
下載附件
proteus截圖
2019-6-9 15:10 上傳
單片機源程序如下:
- #include<reg51.h>
- #include<math.h>
- #define uchar unsigned char
- #define unit unsigned int
- #define lcd_data P0
- #define temp_data P3
- sbit CLK=P1^3;
- sbit ST=P1^2;
- sbit EOC=P1^1;
- sbit OE=P1^0;
- sbit DQ=P1^7;
- sbit lcd_RS=P2^0;
- sbit lcd_RW=P2^1;
- sbit lcd_EN=P2^2;
- sbit Buzz=P1^7;
- sbit right=P2^6;
- sbit left=P2^7;
- sbit Con=P2^5;
- uchar t[2],speed,temperature;
- uchar TempBufferl[12]={0xdf,0x43,'\0'};
- uchar tab[16]={0x20,0x20,0x20,0x54,0x20,0x4d,0x6f,0x6e,0x69,0x74,0x6f,0x72,'\0'};
- uchar V[3];
- /*...延時.......................*/
- void delay(unsigned int x)
- {
- unsigned char i;
- while (x--)
- {
- for(i=0;i<123;i++){;}
- }
- }
- /*...LCD顯示.......................*/
- void delay_20ms(void)
- {
- uchar i,temp;
- for(i=20;i>0;i--)
- {
- temp=248;
- while(--temp);
- temp=248;
- while(--temp);
- }
- }
- void delay_38us(void)
- {
- uchar temp;
- temp=18;
- while(--temp);
- }
- void delay_1520us(void)
- {
- uchar i,temp;
- for(i=3;i>0;i--)
- {
- temp=252;
- while(--temp);
- }
- }
- uchar lcd_rd_status()
- {
- uchar tmp_sts;
- lcd_data=0xff;
- lcd_RW=1;
- lcd_RS=0;
- lcd_EN=1;
- tmp_sts=lcd_data;
- lcd_EN=0;
- lcd_RW=0;
- return tmp_sts;
- }
- void lcd_wr_com(uchar command)
- {
- while (0x80&lcd_rd_status());
- lcd_RW=0;
- lcd_RS=0;
- lcd_data=command;
- lcd_EN=1;
- lcd_EN=0;
- }
- void lcd_wr_data(uchar sjdata)
- {
- while (0x80&lcd_rd_status());
- lcd_RW=0;
- lcd_RS=1;
- lcd_data=sjdata;
- lcd_EN=1;
- lcd_EN=0;
- lcd_RS=0;
- }
- void Init_lcd(void)
- {
- delay_20ms();
- lcd_wr_com(0x38);
- delay_38us();
- lcd_wr_com(0x0c);
- delay_38us();
- lcd_wr_com(0x01);
- delay_1520us();
- lcd_wr_com(0x06);
- }
- void GotoXY(uchar x,uchar y)
- {
- if(y==0)
- lcd_wr_com(0x80|x);
- if(y==1)
- lcd_wr_com(0xc0|x);
- }
- void Print(uchar *str)
- {
- while(*str!='\0')
- {
- lcd_wr_data(*str);
- str++;
- }
- }
- void LCD_Print(uchar x,uchar y,uchar *str)
- {
- GotoXY(x,y);
- Print(str);
- }
- /*...ADC.......................*/
- void display_result(uchar d)
- {
- float a,b,c;
- a=d/100;
- b=(d%100)/10;
- c=d%10;
-
- V[0]=a+'0';
- V[1]=b+'0';
- V[2]=c+'0';
-
- LCD_Print(5,0,V);
-
- }
- /*...主函數.......................*/
- void main(void)
- {
- uchar d;
- uchar p;
- Buzz=0;
- right=0;
- left=0;
- //i=temp_data;
- delay_20ms();
- Init_LCD();
- //display_result(a);
- LCD_Print(0,1,tab);
- //delay(10000);
- TMOD=0x02;
- TH0=0x14;
- TL0=0x00;
- IE=0X82;
- TR0=1;
- EA=1;
- P1=0X3f;
- while(1)
- {
- //i=P3;
- Buzz=0;
- right=0;
- left=0;
- d=temp_data;
- p = 2.0838*d - 240.51;
- ST=0;
- ST=1;
- ST=0;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
光電耦合.7z
(105.27 KB, 下載次數: 37)
2019-6-9 15:07 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|