//LED8*8 scrolling display
//Column scan, low level is valid
/*--------------------------------------------------------------*/
//Include header file
#include #include "74HC595.H" #include /*--------------------------------------------------------------*/ //Global variable definition unsigned char i,flag,t,w,t; unsigned int m,n; unsigned char t1,t2,t3,t4; /*--------------------------------------------------------------*/ //Code library #define num sizeof(buff) //code length unsigned char code aa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char code table2[]={ 0x60,0x60,0x00,0x3E,0x7F,0x41,0x7F,0x3E,/*"0",0*/ 0x60,0x60,0x00,0x42,0x7F,0x7F,0x40,0x00,/*"1",1*/ 0x60,0x60,0x00,0x62,0x73,0x59,0x4F,0x46,/*"2",2*/ 0x60,0x60,0x00,0x22,0x6B,0x49,0x7F,0x36,/*"3",3*/ 0x60,0x60,0x00,0x38,0x3E,0x7F,0x7F,0x20,/*"4",4*/ 0x60,0x60,0x00,0x4F,0x4F,0x49,0x79,0x31,/*"5",5*/ 0x60,0x60,0x00,0x3E,0x7F,0x49,0x7B,0x32,/*"6",6*/ 0x60,0x60,0x00,0x03,0x73,0x79,0x0F,0x07,/*"7",7*/ 0x60,0x60,0x00,0x36,0x7F,0x49,0x7F,0x36,/*"8",8*/ 0x60,0x60,0x00,0x26,0x6F,0x49,0x7F,0x3E,/*"9",9*/ }; unsigned char code table1[]= { //Modulus mode negative code column scan reverse 0x00,0x3E,0x7F,0x41,0x7F,0x3E,0x00,0x00,/*"0",0*/ 0x00,0x42,0x7F,0x7F,0x40,0x00,0x00,0x00,/*"1",1*/ 0x00,0x62,0x73,0x59,0x4F,0x46,0x00,0x00,/*"2",2*/ 0x00,0x22,0x6B,0x49,0x7F,0x36,0x00,0x00,/*"3",3*/ 0x00,0x38,0x3E,0x7F,0x7F,0x20,0x00,0x00,/*"4",4*/ 0x00,0x4F,0x4F,0x49,0x79,0x31,0x00,0x00,/*"5",5*/ 0x00,0x3E,0x7F,0x49,0x7B,0x32,0x00,0x00,/*"6",6*/ 0x00,0x03,0x73,0x79,0x0F,0x07,0x00,0x00,/*"7",7*/ 0x00,0x36,0x7F,0x49,0x7F,0x36,0x00,0x00,/*"8",8*/ 0x00,0x26,0x6F,0x49,0x7F,0x3E,0x00,0x00,/*"9",9*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ }; unsigned char buff[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ 0x00,0x03,0x03,0x3E,0x7F,0x41,0x63,0x22,/*"C",0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/ }; /************************************************************************ The following is the operating procedure of DS18B20 ************************************************************************/ sbit DQ=P3^3; unsigned char time; //Set global variables specifically for strict delay /***************************************************** Function: Initialize the DS18B20 sensor and read the response signal Export parameter: flag ***************************************************/ bit Init_DS18B20(void) { bit flag; //Store the flag of whether DS18B20 exists, flag=0 means it exists; flag=1 means it does not exist DQ = 1; //Pull the data line high first for(time=0;time<2;time++) //Slight delay of about 6 microseconds ; DQ = 0; //Pull the data line from high to low again, and keep it for 480~960us for(time=0;time<200;time++) //Slight delay of about 600 microseconds ; //Send a low-level reset pulse lasting 480~960us to DS18B20 DQ = 1; //Release the data line (pull the data line high) for(time=0;time<10;time++) ; //Delay about 30us (after releasing the bus, you need to wait 15~60us for DS18B20 to output a pulse) flag=DQ; //Let the MCU detect whether the output pulse exists (DQ=0 means existence) for(time=0;time<200;time++) //Delay long enough to wait for the pulse output to complete ; return (flag); //Return the detection success flag } /***************************************************** Function: Read one byte of data from DS18B20 Export parameter: dat ***************************************************/ unsigned char ReadOneChar(void) { unsigned char i=0; unsigned char dat; //Store one byte of data read out for (i=0;i<8;i++) { DQ =1; // Pull the data line high first _nop_(); //Wait for a machine cycle DQ = 0; //When the MCU reads data from DS18B20, pull the data line from high to low to start the read sequence that>>=1; _nop_(); //Wait for a machine cycle DQ = 1; //Pull the data line "artificially" high to prepare for the microcontroller to detect the output level of DS18B20 for(time=0;time<2;time++) ; //Delay about 6us, so that the host can sample within 15us if(DQ==1) dat|=0x80; //If the data read is 1, store 1 in dat else dat|=0x00; //If the data read is 0, store 0 in dat //Store the level signal DQ detected by the microcontroller into r[i] for(time=0;time<8;time++) ; //Delay 3us, there must be a recovery period greater than 1us between two read sequences } return(dat); //Return the decimal data read } /***************************************************** Function: Write a byte of data to DS18B20 Entry parameter: dat ***************************************************/ WriteOneChar(unsigned char dat) { unsigned char i=0; for (i=0; i<8; i++) { DQ =1; // Pull the data line high first _nop_(); //Wait for a machine cycle DQ=0; // Pull the data line from high to low to start the write sequence DQ=dat&0x01; //Use AND operation to get a binary data to be written, // and send it to the data line to wait for DS18B20 sampling for(time=0;time<10;time++) ;//Delay of about 30us, DS18B20 samples from the data line during about 15~60us after being pulled low DQ=1; //Release data line for(time=0;time<1;time++) ;//Delay 3us, at least 1us recovery period is required between two write sequences dat>>=1; //Shift each binary bit in dat right by 1 bit } for(time=0;time<4;time++) ; // Delay a bit to give the hardware some time to react } void ReadyReadTemp(void) { Init_DS18B20(); //Initialize DS18B20 WriteOneChar(0xCC); // Skip reading the serial number and column number WriteOneChar(0x44); // Start temperature conversion for(time=0;time<100;time++) ; //Temperature conversion takes a while Init_DS18B20(); //Initialize DS18B20 WriteOneChar(0xCC); //Skip the operation of reading the serial number and column number WriteOneChar(0xBE); //Read the temperature register, the first two are the low and high bits of the temperature respectively } /*--------------------------------------------------------------*/ //Display function void Display(void) { if(flag==2){ Ser_IN[[aa[i]]]; //Column scan data Ser_IN(buff[i + n]); //Look up the table to get the row scan data Par_OUT(); //Output display i++; if(i == 8) i = 0; //Loop scan m++; if(m == 100) {m = 0; n++;} //Scrolling speed control if(n == num-7) { n = 0; // loop display flag=1; } } } /*--------------------------------------------------------------*/ //Timer initialization void T_init(void) { TMOD = 0x11; TH0 = 0xfc; //1MS TL0 = 0x66; EA = 1; // Enable CPU interrupts ET0 = 1; //Timer 0 interrupt is enabled TR0 = 1; } /*--------------------------------------------------------------*/ //Timer interrupt service void T0_intservice(void) interrupt 1 using 0 { TH0 = 0xfc; TL0 = 0x66; Display(); } /*--------------------------------------------------------------*/ //Main function void main (void) { unsigned char TL; //Store the low temperature bit of the register unsigned char TH; //Store the high temperature bit of the register unsigned char TN; //Store the integer part of the temperature unsigned char TD; //Store the decimal part of the temperature flag=1; T_init(); while(1){ if(flag==1){ ReadyReadTemp(); //Read temperature preparation TL=ReadOneChar(); //Read the low bit of the temperature value first TH=ReadOneChar(); //Then read the high bit of the temperature value TN=TH*16+TL/16; //Actual temperature value = (TH*256+TL)/16, i.e.: TH*16+TL/16 //This is the integer part of the temperature, the decimal part is discarded TD=(TL%16)*10/16; //Calculate the decimal part of the temperature, multiply the remainder by 10 and divide by 16 to get the integer. t1=TN/100; // take the hundredth place t2=(TN%100)/10; //Take the tens digit t3=TN%10; //get the unit digit t4=TD; flag=0; } if(flag==0){ for(w=1;w<6;w++){ if(w==5){ flag=2; } for(t=0;t<8;t++){ switch(w){ case 1: buff[t+(8*w)]=table1[(8*t1)+t]; break; case 2: buff[t+(8*w)]=table1[(8*t2)+t]; break; case 3: buff[t+(8*w)]=table1[(8*t3)+t]; break; case 4: buff[t+(8*w)]=table2[(8*t4)+t]; break; } } } } }; } //Note: 74HC595 driver // ''' ''' //Note: MR master reset connects to the positive pole of the power supply, OE enable terminal, output valid connects to the negative pole of the power supply /*--------------------------------------------*/ #ifndef '''74HC595_H''' #define '''74HC595_H''' /*--------------------------------------------*/ sbit SD = P1^4; //Serial data input sbit ST_CK = P1^5; //Storage register clock input sbit SH_CK = P1^6; //Shift register clock input /*--------------------------------------------*/ //Definition of digital tube break code and bit code //unsigned char code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00,0xff};
Previous article:Digital tube dynamic and static display principle
Next article:51 single-chip remote control decoding is displayed through the computer serial port--C51 source code
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- Circuit Design Considerations
- [National Technology Low Power Series N32L43x Review] 07. Automatically calculate configuration parameters through CAN communication baud rate
- There is a surprise: If you encounter a Labview problem and no one is helping you, try this
- [Atria AT32WB415 Review] 3. Serial port print information printf
- [GD32L233C] + 3. Use RTThread
- Review summary: Hongmeng development board Neptune
- PWM output of MSP430 library timer TA
-
[NXP Rapid IoT Review] +
NXP Rapid IoT, a simplest cloud server prototype - Welcome to chat with me, guys~
- EEWORLD University ---- Computer Control Technology