Some knowledge points of 51 single chip microcomputer

Source: Internet
Author: User

1. Single chip microcomputer chip model: STC 89C51RC 40c-pdip 0707

STC--STC Company, other prefixes include at, Winbond, etc.

8--based on 8051 core chip

9--indicates that the internal flash E2prom memory is included

c--indicates that the device is a CMOS product

5--fixed unchanged

The 4kb,2 represents the internal storage space of the chip, and the 1 is 8kb,3 to 12KB

RC--STC single-chip internal RAM (random read-write memory) is 512B, and rd+ indicates that internal RAM is 1280B

The 40--indicates that the external crystal oscillator can be connected to 40MHz, and the value of the at MCU is generally 24MHz.

c--product grade, Commercial grade (I: Industrial grade, A: Automotive Products, M: Military grade)

pdip--package model, PDIP is dual-inline

0707--07 7th Week

2, 51 single-chip computer P-Port

There are four categories, namely, P0, P1, P2, P3 mouth.

P0 Port: Bidirectional 8-bit tri-state I/O port, because there is no pull-up resistor inside the P0, is high-impedance state, so can not be normal output high and low level, so the group I/O in use to external pull-up resistor, general access to 10kω pull-up resistor;

P1 mouth, P2 mouth, P3 mouth: quasi-bidirectional I/O, with pull-up resistor, this interface output does not have a high resistance state, input can not be locked, it is not true bidirectional I/O port. The mouth in the use as input before, to the mouth to write 1 operation, and then the microcontroller inside can correctly read out the external signal, that is, to make its first a "preparation" process.

3, TTL, CMOS level standard

TTL level threshold:

(1) vohmin = 2.4v,volmax = 0.4V

(2) vihmin = 2.0v,vilmax = 0.8V

CMOS level critical value:

(1) vohmin = 4.99v,volmax = 0.01V

(2) vihmin = 3.5v,vilmax = 1.5V

CMOS circuits do not use the input terminal can not be suspended, otherwise it will cause logic confusion. In addition, the power supply voltage of the CMOS integrated circuit can vary in a larger range, thus the requirements for the power supply are not as stringent as TTL ICS.

The CMOS level can drive the TTL level, but the TTL level does not drive the CMOS level and requires a pull resistor.

4, SFR, sfr16, sbit description

SFR ——-declare a 8-bit register, such as: SFR SCON = 0x98;scon is a microcontroller serial control register, this register in the MCU memory address is 0x98. After such a declaration, the Scon operation is later directly equivalent to the register at the 0x98 address.

SFR16--16-bit Special function Register declaration, such as: sfr16 T2 = 0xCC; T2 Register is declared, its starting address is 0xCC. (T2 is a timer register)

sbit--defines one of the internal registers (also the register can be bit-manipulated), such as: sbit TI = scon^1; The SCON is a 8-bit register, and the scon^1 is the secondary low of this 8-bit register.

5. Header files commonly used in C51

Reg51.h, Reg52.h, MATH.H, ctype.h, stdio.h, Stdlib.h, absacc.h, intrins.h

Generally written: #include <reg52.h>

6. Introduction of several cycles of single-chip microcomputer

(1) Clock cycle: As the name implies, is the inverse of the crystal frequency;

(2) Status cycle: Twice times the clock cycle;

(3) Machine cycle: 12 clock cycles;

(4) Instruction period: The time required for the CPU to execute an instruction is usually 1~4 machine cycle.

7, about the interruption

52 single-chip interrupt source has 6, the following 1~6 also according to the priority of the interrupt is arranged, (1) the highest (6) the lowest

(1) int0--external interrupt 0, introduced by P3.2 Port

(2) int1--external interrupt 1, introduced by P3.3 Port

(3) t0--Timer/Counter 0 interrupt

(4) t1--Timer/Counter 1 interrupt

(5) ti/ri--serial port Interrupt

(6) t2--Timer/Counter 2 interrupt

Related registers for interrupt control

(1) interrupt allow register IE

(2) Interrupt priority Register IP

(3) Timer/Counter operating mode register TMOD

(4) Timer/Counter control register Tcon

The corresponding bit bits of the above 4 registers can be set to interrupt the way and function, etc., the actual use is not so troublesome, for example, as follows:

//Interrupt ExamplevoidMain () {Tmod=0x01;//set the mode of operation of timer 0 1 (M1M0)TH0 = (65536-45872)/ the;//Loading initial value, timing 50ms, crystal oscillator 11.0592MHzTL0 = (65536-45872)% the; EA=1;//Open main SwitchET0 =1;//Open Timer 0 InterruptTR0 =1;//Start Timer 0     while(1);//program stops here waiting for interrupts to occur}voidT0_time () Interrupt1{TH0= (65536-45872)/ the;//re-install initial valueTL0 = (65536-45872)% the; Num++;//num Self-add    if(num== -)//if it's 20 times, it means that 1s is here.{num=0;//num Clear 0Led1 = ~led1; }  }

Calculation of interrupt initial value

Assuming that the microcontroller clock frequency is 12MHz, and the machine cycle is 12 clock cycles, this time a machine cycle is 1us. Jina TH0 and TL0 need 216-1 = 65535, when counting to 65535, the counter will overflow in the next pulse and then request an interrupt to the CPU. Therefore, the overflow requires a total of 65536us. Assuming that we are now counting 50ms, we need to fill in an initial value, counting 50,000 times on the basis of this initial value to just overflow the interrupt request. This is the reason for the initial value.

The exact method of putting the initial value is as follows:

THx = (65536-n)/256 TLx = (65536-n)%256

8, take out the corresponding bit C language wording

/*

Two digits out of 10 digits

Three digits out of hundreds, 10 digits, digits

Four digits out of the hundred, 10 digits, single digit

*/

num is the corresponding number

Double digit

Shi = NUM/10;

GE = num% 10;

Three-digit number

Bai = num/100;

Shi = NUM%100/10;

GE = num%10;

Four-digit number

Qian = num/1000;

Bai = num/100%10;

Shi = num/10%10;

GE = num%10;

9, _nop_ ();

It is equivalent to a machine cycle, to use this function, to bring the top file #include<intrins.h>

Some knowledge points of 51 single chip microcomputer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.