【Keil5 C51】AT89C52 water lamp experiment (call C51 library function _crol_)

Publisher:SereneWhisperLatest update time:2020-05-14 Source: eefocusKeywords:Keil5  C51  AT89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction to the _crol_ function

Cx51 User’s Guide


Summary

#include


unsigned char _crol_ (

  unsigned char c,        /* character to rotate left */

  unsigned char b);       /* bit positions to rotate */


Description

The _crol_ routine rotates the bit pattern for the character c left b bits. This routine is implemented as an intrinsic function (starting from bit 1 in the c variable and moving left b bits at a time, for example, when b = 1, the string of numbers will move like this: 1111110–>11111101)


Return Value

The crol routine returns the rotated value of c.


Example

#include


void test_crol (void) {

  char a;

  char b;


  a = 0xA5;

  b = _crol_(a,3); /* b now is 0x2D */

}


Flowing light code

Using AT89C52 chip, crystal oscillator is 11.0592MHz


#include

#include


#define uint unsigned int

#define uchar unsigned char

void delay(uint time);  

void main()

{

uint led = 0xfe; //11111110 

while(1){

P1 = led; //11111110 Turn on the first light of P1 port first

delay(500); //delay 0.5s

led = _crol_(led,1); //Call the _crol_ function to shift the led variable left from the first one 11111110-->11111101

//Return to led, now led = 11111101

}

}


void delay(uint time)  //delay = 1 ms 0.001s

{

uint x;

uint the;

uint z;

for(z = time; z > 0; z--){

for(x = 1; x > 0; x--){

for(y = 115; y > 0; y--){}

}

}

}


Proteus simulation diagram

insert image description here
insert image description here

Keywords:Keil5  C51  AT89C52 Reference address:【Keil5 C51】AT89C52 water lamp experiment (call C51 library function _crol_)

Previous article:51 MCU Getting Started Tutorial (2) - Implementing a Flowing Light
Next article:51 MCU Tutorial The first 51 program: Light up a light-emitting diode

Recommended ReadingLatest update time:2024-11-15 07:51

P10 dot matrix screen C51 single chip microcomputer program
P10 dot matrix screen C51 program 1/4 scan, four scans down, 1 channel 16 lines, data low OE high (04-P16-08) suitable for HUB12 interface monochrome P10 serial port mode 0, normal left shift, brightness speed adjustable, 6 IO ports, using STC8F1K08, up to 231 words. The actual picture is as follows:   The
[Microcontroller]
P10 dot matrix screen C51 single chip microcomputer program
Design of smoke alarm based on AT89C52 and MQ-2 smoke sensor
This paper introduces a smoke alarm design based on AT89C52 single chip microcomputer and MQ-2 semiconductor resistor smoke sensor. The smoke alarm has functions such as sound and light alarm, concentration display and serial communication with the host computer. It has a simple structure, low price, stable performa
[Microcontroller]
Design of smoke alarm based on AT89C52 and MQ-2 smoke sensor
C51 MCU writes an external interrupt (entry-level MCU)
Code section void main() { /*---------------EA,IT,EX must write-------------*/ EA=1; // Enable general interrupt IT1=1; //interrupt trigger mode             //=0 is low level trigger, =1 is falling edge trigger   EX1=1; //External interrupt enable bit       while(1) {     led1=0;     } }     void int1
[Microcontroller]
C51 MCU writes an external interrupt (entry-level MCU)
Analysis of the calculation method of C51 microcontroller delay time
Different types of variables can be used in C programs for delay design. After experimental testing, using the unsignedchar type has more optimized code than unsignedint. When using it, unsignedchar should be used as a delay variable. Take a microcontroller with a crystal oscillator of 12MHz as an example. If the crys
[Microcontroller]
MCU Strategy 3 - Getting Started with C51
1. Background With the development of the times, people hope to integrate CPU, RAM and other devices into one platform to work, and the single-chip microcomputer was born. So far, there are many types of single-chip microcomputers on the market, and the inherited functions have also evolved in different directions a
[Microcontroller]
MCU Strategy 3 - Getting Started with C51
Installation of Keil C51
1 Introduction Used to write microcontroller loader Keil is divided into two versions: MTK and C51 Please pay attention when downloading, there is no C51 series MCU in the MTK version 2. Download 1) Download from the official website Official download address: https://www.keil.com/download/product The official web
[Microcontroller]
Installation of Keil C51
How to calculate the delay time of the C51 microcontroller?
Different types of variables can be used in C programs for delay design. After experimental testing, the use of unsigned char type has more optimized code than unsigned int. Unsigned char should be used as a delay variable when used. Take a microcontroller with a crystal oscillator of 12MHz as an example. The crystal
[Microcontroller]
LCD1602 LCD display C51 modular program + circuit diagram
The following is the circuit diagram of 51 single chip microcomputer driving 1602 LCD: The program has 3 files in total:   /********************** lcd.h header file **********************/ #ifndef _LCD_H_ #define _LCD_H_ #include reg51.h extern void lcd_init(); extern void lcd_busy(); extern void lcd_write_dat(un
[Microcontroller]
LCD1602 LCD display C51 modular program + circuit diagram
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号