Digital-to-Analog Converter ADC08009 Application

Publisher:星光闪耀Latest update time:2024-08-14 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 #include //header file

2 #define uchar unsigned char //macro definition of unsigned character type

3 #define uint unsigned int //macro definition unsigned integer

4 code uchar seg7code[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //Display segment code digital tube word and

5 uchar wei[4]={0XEf,0XDf,0XBf,0X7f}; //bit control end //bit control code

6 sbit ST=P3^0; //A/D start conversion signal

7 sbit OE=P3^1; //Data output enable signal

8 sbit EOC=P3^2; //A/D conversion end signal

9 sbit CLK=P3^3; //clock pulse

10 uint z,x,c,v,AD0809, date; //define data type

11 /************************************************ ******************

12 Delay function

13 ************************************************* *******************/

14 void delay(uchar t)

15 {

16 uchar i,j;

17 for(i=0;i

18 {

19 for(j=13;j>0;j--);

20 { ;

twenty one }

twenty two }

twenty three }

twenty four /************************************************ **********************

25 digital tube dynamic scanning

26 ************************************************* ************************/

27 void xianshi() //Display function

28 {

29 uint z,x,c,v;

30 z=date/1000; //Calculate the thousandth place

31 x=date%1000/100; //Calculate the hundreds place

32 c=date%100/10; //Find the tenth digit

33 v=date%10; //Find the unit digit

34

35 P2=0XFF;

36 P0=seg7code[z]&0x7f;

37 P2=wei[0];

38 delay(80);

39 P2=0XFF;

40 P0=seg7code[x];

41 P2=wei[1];

42 delay(80);

43 P2=0XFF;

44 P0=seg7code[c];

45 P2=wei[2];

46 delay(80);

47 P2=0XFF;

48 P0=seg7code[v];

49 P2=wei[3];

50 delay(80);

51 P2=0XFF;

52 }

53 /************************************************ *************************

54 CLK oscillation signal

55 ************************************************* *************************/

56 void timer0() interrupt 1 //Timer 0 working mode 1

57 {

58

59 TH0=(65536-2)/256; //Reload count initial value

60 TL0=(65536-2)%256; //Reload count initial value

61 CLK=!CLK; //Invert

62 }

63

64 /************************************************ *************************

65 Main function

66 ************************************************* *************************/

67 void main()

68 {

69 TMOD=0X01; //Timer interrupt 0

70

71 CLK=0; //The initial value of the pulse signal is 0

72 TH0=(65536-2)/256; //initial value of high 8 bits of timing time

73 TL0=(65536-2)%256; //initial value of the lower eight bits of the timing time

74 EA=1; //Open CPU interrupt

75 ET0=1; //Open T/C0 interrupt

76 TR0=1;

77 while(1) // infinite loop

78 {

79 ST=0; // Make the acquisition signal low

80 ST=1; //Start data conversion

81 ST=0; //Stop data conversion

82 while(!EOC); //Wait for data conversion to complete

83 OE=1; //Enable data output signal

84 AD0809=P1; //Read data

85 OE=0; //Turn off data output enable signal

86 if(AD0809>=251) //The voltage displayed cannot exceed 5V

87 AD0809=250;

88 date=AD0809*20; //The data value displayed by the digital tube, where 20 is the milliampere value of the collected data

89 xianshi(); //digital tube display function

90

91 }

92 }


Reference address:Digital-to-Analog Converter ADC08009 Application

Previous article:Customize the reg52.h header file (key knowledge points of microcontroller learning)
Next article:Smoke sensor based on AT89C51 microcontroller

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号