8051 microcontroller 4-bit led binary counter
You can use any other of 8051 series microcontrollers like 89c51, 89s51, 89s52 etc for this project. A slight change in code header file is required if you switch from 8051 to 8052 microcontroller. For 89c51 and 89s51 header file is reg51.h. But for 89c52 and 89s52 header file is reg52.h. So please be sure first which microcontroller you are using in your project and include the correct header file i code. This header file is only to be included if you are using keil as software to program your microcontroller. I am using keil u-vision3 for this project.
8051 microcontroller Led’s Binary counter – code
The statement P1=0x01 is making port#1 pin#0 high. The statementP1=0x01 is in hexadecimal form. In statement 0x means that the number is in hexadecimal from and the number comes right after 0x which in our case is 01. 01 in binary is equal to 01=00000001.
After theP1=0x01 statement comes 02=00000010 03=00000011 04=0000100 05=00000101 06=00000110 07=00000111 08=00001000 09=00001001 0A=00001010 0B=00001011 0C=00001100 0D=00001101 0E=00001110 0F=00001111. These bits are continuously being written to the port-1 pins with some delay in each statement. Since led’s are connected as output to port-1 the binary pattern will appear on led’s This logic makes them on and off and it seams to be counter running on them. Project circuit diagram is below.
4-bit Binary counter above same code in decimal form
8-bit binary counter on led’s with 8051 microcontroller
Filed Under: 8051 Microcontroller, Microcontroller Projects