C8051F320 Learning, single-chip microcomputer is not only clock, IO, serial, USB and other peripheral usage

Source: Internet
Author: User

Clock io (input, output, how to configure) IODigital and analog resources can be passed through 25 I/O pins (C805 1f3 2 0), each port pin can be defined as 1 General Purpose I/O (GPIO) or 0 analog inputsAll port I/O are resistant to 5V voltage port I/O unit can be configured to Open drain or push-pull mode, port output mode register Pnmdout set, n = 0,1, 2, 3p1mdout |= 0x0f;//0000 1111 the 0-3 port of the P1 is 1.That is, push-pull output mode p2mdout |= 0x0c;//0000 1100 corresponding P2.2, P2.3 push-pull output registers XBR0 and XBR1 are used to allocate physical I/O pins for digital I/O resources   Pnmdin Select the input mode (analog or digital) for all port pins   Note: For ports P0, P1, and P2.0 ~ P2.3 working on standard port I/O input/output mode, cross switch required
Must be enabled. When the crossover switch is disabled, the port output driver is disabled. P2.4 ~ P2.7 and P3.0 are always standard
GPIO Use
 XBR1 |= (1<<6);

USB Clock  C8051F 320/1 has a programmable Internal oscillator, an external oscillator drive circuit, and a 4 times-fold clock multiplier
The OSCICN and OSCICL registers can be programmed to enable/disable the internal oscillator and adjust its output frequency (
As shown in 13.1). The system clock (SYSCLK) can come from an internal oscillator, an external oscillator circuit, or a 4 times-fold clock multiplier
Two frequency. The USB clock (USBCLK) can come from an internal oscillator, an external oscillator circuit, or a 4 times-fold clock multiplier.
Table 13.3 shows the electrical characteristics of the internal oscillator once the frequency of the internal oscillator is modified, it can no longer be used as a USB clockThe 4 times-fold clock multiplier allows the 48MHz clock required to generate full-speed USB communication using a 4 times-M Hz oscillator with the CLKMUL register configured with a clock multiplier of the time-of-use. The steps to configure and enable the 4 times-fold clock multiplier are as follows:
1. Resets the clock multiplier by writing 0x00 to the Register Clkmul.
2. Select the input of the clock multiplier with the Mulsel bit.
3. Mulen-bit Enable clock multiplier (clkm UL | = 0x80).
4. Delay is greater than 5µs.
5.  Initialize the clock multiplier with the Mulinit bit (Clkmul | = 0 x C 0).
6. Query Waiting Mulrdy = ' 1 '. It's all the same. Multiply register configuration void clock_init (void)
{
int8u i;
if ((Clkmul & (1<<5))) return;//If the multiplication register is locked, return
Clkmul = 0;
Clkmul |= (1<<7);//clock multiplier enable bit
for (i = 0; i <; i + +);//delay
Clkmul |= 0xc0;//1100 0000, initialize clock multiplier
for (i = 0; i <; i + +);
while (!) ( Clkmul & (1<<5));//Clock multiplier stable, Mulrdy readout value is ' 1 '
Clksel = (2<<0);
} Serial Port  void Port_init (void)
{
XBR1 = 0x40; Enable Crossbar and Weak pullups
XBR0 = 0x01;
P0mdout |= 0x10; Set TX pin to Push-pull
} void Uart0_init (void)
{
SCON0 = 0x10; 0x0001 0000The logic level of the 8-bit UART no stop bit is ignored UART0 receive allowsScon0:8-bit variable bit rate
Level of STOP bit is ignored
// RX enabled
Ninth Bits is zeros
Clear RI0 and TI0 bits//configuration t1m, sca1:0if (sysclk/baudrate/2/256 < 1) {
TH1 =-(SYSCLK/BAUDRATE/2);
Ckcon |= 0x08; // t1m = 1; sca1:0= XX
} else if (sysclk/baudrate/2/256 < 4) {
TH1 =-(SYSCLK/BAUDRATE/2/4);
Ckcon &= ~0x0b; t1m = 0; sca1:0 = 01
Ckcon |= 0x01;
} else if (sysclk/baudrate/2/256 < 12) {
TH1 =-(SYSCLK/BAUDRATE/2/12);
Ckcon &= ~0x0b; t1m = 0; sca1:0 = 00
} else if (sysclk/baudrate/2/256 < 48) {
TH1 =-(SYSCLK/BAUDRATE/2/48);
Ckcon &= ~0x0b; t1m = 0; sca1:0 = 10
Ckcon |= 0x02;
} else {
while (1);  Error. Unsupported baud rate
}

TL1 = TH1; Init Timer1
Tmod &= ~0xf0; Tmod:timer 1 in 8-bit autoreload
Tmod |= 0x20;
TR1 = 1; START Timer1
TI0 = 1; Indicate TX0 ready
} ADCConfigure with configurator: ADC0CN = 0x02; ADC0 disabled, normal tracking,
Conversion triggered on TMR2 overflow ADC0 Trigger with clockEIE1 |= 0x08; Enable ADC0 conversion complete int. Interrupt ConfigurationIn Adcmux set there choose P2.4, and GND. PIN Configurationamx0p = 0x0C; ADC0 positive input = P2.4
amx0n = 0x1F; ADC0 Negative input = GND
i.e., single ended modeP2mdin = 0xef;//p2.4 is set to analog input, Portinit also the serial port configuration and Clock 2 I²cvoid Smbus_init (void);
void Smbus_isr (void);

C8051F320 Learning, single-chip microcomputer is not only clock, IO, serial, USB and other peripheral usage

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.