WCH MCS-51(8051) USB MCUs

Go To Last Post
29 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Although these cheap chips have been out for a couple years, I've not seen a lot of English documentation about how to use them.  I recently picked up a couple of modules (CH551 & CH552) and wrote about how to get started with them.

http://nerdralph.blogspot.com/20...

 

I was surprised with how easy the architecture was to learn; it only took me a couple of days to get to the point where I can understand and start to optimize the .asm code output of SDCC.  One thing I didn't realize before buying these chips is that the 8051 is not just an instruction set, it's an architecture.  That made understanding the timer and UART registers as easy as looking at 8051 UART example code instead of trying to understand WCH datasheet translated from Chinese.  Even much the Atmel AT89LP51/52 datasheet is helpful for programming the WCH chips.  When it comes to asm programming, I really like the consistent architecture compared to the AVR tiny & mega.  A lot of the time I spend writing AVR asm code is comparing datasheets to for things like checking the IO registers to see if they are always below 0x3F so I can use in/out instructions, or if I have to use sts/lds because one of the MCUs has the register in the high address space.  I also like that a lot of instructions to not impact the CPU status flags (like Carry & Overflow), so it is easy to write short ISRs without prologues & epilogues of push & pop.

 

With the soft UART work I've done on the AVR platform, I had recently been writing asm code to implement parity.  On the MCS-51, the status register has a Parity bit which updated with the parity of the accumulator.   So parity calculation just requires moving the data to the accumulator and reading the P bit.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
... I've not seen a lot of English documentation about how to use them.
by an operator of CH552 and CH554

How To Program A Really Cheap Microcontroller | Hackaday

 


MCU series chip - Jiangsu Qinheng Co., Ltd. (WCH)

...

 

 8-bit enhanced USB series MCU (USB + Touchkey + Type-C + ADC)

 

...

WCH - CH55x - ElectroDragon

Blinkinlabs, LLC · GitHub

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
..  I recently picked up a couple of modules (CH551 & CH552)..

WCH also  have a newer, faster, CH54x series, but I've not seen modules yet with those, and they only list  low volumes of  QFN28 CH459 at lcsc 

I also noticed SDCC recently added 64bit variable support, which is rarely used, but nice when you need it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

ralphd wrote:
much the Atmel AT89LP51/52 datasheet is helpful

Have you also seen the Philips documentation - the so-called "bible" for the 8051?

 

The links here are long dead, but googling the PDF filenames will find you copies; eg,

 

http://ecee.colorado.edu/~mcclurel/p8051pg.pdf -  80C51 family programmer’s guide and instruction set

 

http://ecee.colorado.edu/~mcclurel/p8051hw.pdf -  80C51 family hardware description

 

http://ecee.colorado.edu/~mcclurel/p8051arc.pdf -  80C51 family architecture

 

 

EDIT

 

Fix links

 

#8051bible

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jul 2, 2020 - 09:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
  Even much the Atmel AT89LP51/52 datasheet is helpful for programming the WCH chips. 

There is also this English link, for the CH552 peripherals 

https://usermanual.wiki/Document/CH55420manual20english.303049169/help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I was surprised with how easy the architecture was to learn;

Don't be surprised ---that's why it has been a leader and one of the top chips for decades.   It's always been saluted for effective bit manipulating.  Whole companies were founded on the backs of the 8051 or to produce 8051 chips....worth more than cash.

 

https://www.handsontec.com/pdf_learn/8051_Final_Word.pdf

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

the 8051 is not just an instruction set, it's an architecture.

 

Well, more or less, anyway.  The original 8051 had  the 4 IO Ports, UART, and three timers, and almost all of the copies have retained compatibility with those basics (as much as pin count permits, anyway.)

It's when you get beyond that that things get interesting - many newer 8051 variants have modes where they use fewer than 12 clocks per instruction cycle, but doing so immediately after poweron would make them less backward-compatible, so you need to use the individual datasheets for things like that, plus any extra peripherals...

 

Before there was the Arduino, there was the Basic Stamp, and before the Stamp were the 80c52-Basic boards - 8052 chips with a basic interpreter programmed in their ROM, capable (usually) of using external RAM and EPROM (UV!) to hold things like home automation software.  Only a couple hundred bucks (about $30 for the basic chip, IIRC!), and you could connect them right up to your teletype!  (for some reason, 8052-basic in flash-based 8051s never caught on.)  8051 chips with random stuff in their ROM would also show up on the surplus market for cheap, and could be strapped into "external memory" mode to ignore their ROMs and run user code.   PJRC (of Arduino Teensy fame) had some 8051 boards as their first products.  I used to think about putting a reduced 8052-basic in one of the tiny chips (AT89c4051, for example), but never got around to it (and better things have replaced it.)

 

 

Oh yeah; when web-searching for 8051 info, don't forget the various synonyms: 8031 (ROMless), 8052 (more ROM), 8752 (EPROM), and the various CMOS versions (80c52, etc.)

 

 

It looks like NXP (who bought Philips) still has datasheets: https://www.nxp.com/docs/en/data...

These days 8051 cores appear in a lot of unlikely places (MP3 chips, SD card readers, etc.)

SiLabs probably owns the enhanced 8051 market - their whole EFM-8 line is 8051 architecture.  They have a free version of the Keil compiler available as well, which I'm sure no one would possibly consider using for non-SiLabs chips!

 

 

Definitely from a time when chip architectures were defined with the assembly language programmer in mind; I'm not surprised that you like it.

(I've been writing an ARM Cortex-M disassembler recently.   SOOOOO UGLY!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might like this:

https://www.maximintegrated.com/en/products/microcontrollers/DS89C430.html

The DS89C430 and DS89C450 offer the highest performance available in 8051-compatible microcontrollers. They feature newly designed processor cores that execute instructions up to 12 times faster than the original 8051 at the same crystal speed. Typical applications will experience a speed improvement up to 10x. At 1 million instructions per second (MIPS) per megahertz, the microcontrollers achieve 33 MIPS performance from a maximum 33MHz clock rate.

 

They even include a bootloader,  You can simply use with terraterm or hyperterminal to upload your file.  Take a look at the price--you'll be surprised & probably pick yourself off the floor.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everything old is new again.........

Next we'll be reminiscing about pic 12/14/16/18 architecture! I stumbled across a 8021 last week and did disassembly of some 8048 code recently. And have been working with a capricorn cpu of late.

 

The 8051 was good until you needed external (or xram in some variants) memory. Then it got ugly. real fast. Also you had to be lean with your stack. Again, some variants sort of fixed that. If you stayed within the confines of the internal ram, it was a delight to write asm for - whilst the instruction set was far from orthogonal, there always seemed to be an instruction that did what you wanted. The AVR fixed most of those issues, was faster and had cheap C compilers.

 

Another flashback - those infernal open collector (drain) drivers of the 8051. You can have them.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First about all 51 chips for the last 30 years+ have been 52's the 51 now just tell about the family 

 

About Basic you seem to forget the 8052AH-BASIC that is a true Intel part.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The cmos ones were luxury! I've got an Intel hmos 8052AH-BASIC chip and the official manual. Even more obscure is the Nat Semi INS8073 with tiny basic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

ralphd wrote:
much the Atmel AT89LP51/52 datasheet is helpful

Have you also seen the Philips documentation - the so-called "bible" for the 8051?

 

The links here are long dead, but googling the PDF filenames will find you copies; eg,

 

http://ecee.colorado.edu/~mcclurel/p8051pg.pdf -  80C51 family programmer’s guide and instruction set

 

http://ecee.colorado.edu/~mcclurel/p8051hw.pdf -  80C51 family hardware description

 

http://ecee.colorado.edu/~mcclurel/p8051arc.pdf -  80C51 family architecture

 

 

 

Thanks for the reference; they do look well written.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think Intel made the BASIC chip other than hmos (the H in AH is for hmos).

 

But I gave up the BASIC was to slow for what I wanted, and I used a pascal compiler, I can't remember the name of it.

 

Add:

I still have one or two here

Last Edited: Fri. Jul 3, 2020 - 01:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

I was surprised with how easy the architecture was to learn;

Don't be surprised ---that's why it has been a leader and one of the top chips for decades.   It's always been saluted for effective bit manipulating.  Whole companies were founded on the backs of the 8051 or to produce 8051 chips....worth more than cash.

 

https://www.handsontec.com/pdf_learn/8051_Final_Word.pdf

 

 

 

I did a quick skim of that document and it seems pretty good, other than covering Keil instead of SDCC.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:

Definitely from a time when chip architectures were defined with the assembly language programmer in mind; I'm not surprised that you like it.

(I've been writing an ARM Cortex-M disassembler recently.   SOOOOO UGLY!)

 

It's simple not just for the assembly programmer, but also for compiler/linker/disassembler developers.  The instruction coding is simple.

MOV Rn, immediate is encoded with the register number as the lower 3 bits of the first byte, and the immediate data as the 2nd byte.

The AVR LDI instruction splits the immediate data into two nibbles stored in the low and high bytes.  The AVR instruction set manual doesn't specify which is the high nibble and which is the low nibble, so I had to figure it out by looking at a hex dump of the binary.  If the Arm encoding is similiar, writing a disassembler would be rather painful.  With the simple instruction encoding of the 8051, writing a compiler may be a manageable enough project that I can tackle.  I've found a couple open-source C99 parsers, so I'd just have to focus on the back end.  To simplify development and global optimization, I'd probably combine all the output into a single big .asm file.

 

Attachment(s): 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
It's simple not just for the assembly programmer, but also for compiler/linker/disassembler developers. 

Hmmm ...

 

The biggest problem for 'C' compiler developers is the fact that it has virtually no hardware stack to speak of - so you can't really do the standard 'C' thing of passing parameters on the stack, and having automatics on the stack.

 

Keil have some fun techniques to get around this - which bring some Gothas! for beginners & the the unwary ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The stack and the small amount of iram will bite you. Keil and IAR did some tricks to make it work. I don’t miss having to navigate the minefield of writing C for that architecture.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The stack and the small amount of iram will bite you. Keil and IAR did some tricks to make it work. I don’t miss having to navigate the minefield of writing C for that architecture.

 

The ATtiny13A only has 64 bytes of RAM, and I've not found that to be a problem.   Having the stack grow up instead of down is not as convenient, but my plan is to set the stack to 0x80 and keep the lower half of iRAM for variables.  With 8 registers (x4 banks) + accumulator + DPTR, there's not much reason to use the stack for argument passing.

 

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The stack and the small amount of iram will bite you. Keil and IAR did some tricks to make it work. I don’t miss having to navigate the minefield of writing C for that architecture.

 

If you thought C was bad you should have seen the contorted mess that was the output from PL/M51!

 

That said, I've always had a soft spot for the '51 range. As observed, there always seems to be the right instruction to do what you want when writing in assembler.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The 8051 was good until you needed external (or xram in some variants) memory

Modern variants/derivatives all have on-chip RAM, but the instruction set still accesses it as XRAM (XDATA) - which which was another constant cause of confusion for newbies!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The register banks were the silver bullet for fast isrs. Since the original 12 clock cores moved at a leisurely pace ( by today’s standards), Intel built in a few tricks to help things along.
keil and IAR used ram to pass variables rather than stack. This was one of the rarer cases where a compiler could beat a human in that it analysed the usage to minimise the amount of ram it used. It also meant you couldn’t do recursion.

It’s taken me years to unlearn all the contortions I did to coax the compiler into producing reasonable code. Of course, compilers have got smarter and the architectures suit compiled languages better.
Ralph, I’d recommend having a play with the Keil or IAR compilers to see what they do. They are probably considered ‘state of the art’ for the 8051.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Of course, compilers have got smarter and the architectures suit compiled languages better.

When it comes to the AVR targets, gcc has gotten stupider, not smarter somewhere after avr-gcc 7.3.

 

Kartman wrote:
Ralph, I’d recommend having a play with the Keil or IAR compilers to see what they do. They are probably considered ‘state of the art’ for the 8051.

I'll keep that in mind after I've toyed with it a bit more.  I want to see what I can come up with first, and then I'll look to see if Keil or IAR have a better way. 

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All discussion of 8051 reminds of the Godfather III movie where Don Michael Corleone says, " just when I thought I was out, they pull me back in".

 

What 8051 assembler program are you using?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gcc has gotten stupider, not smarter somewhere after avr-gcc 7.3.

That's an interesting comment, can you say why or what has been made worse compared to earlier releases?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>> gcc has gotten stupider, not smarter somewhere after avr-gcc 7.3.

That's an interesting comment, can you say why or what has been made worse compared to earlier releases?

https://gcc.gnu.org/bugzilla/sho...

 

Compilers are easier for 8051, because you quickly resign yourself to the code always being bad :-(
(or rather, not really able to do the things one expects a modern compiler to be able to do, I guess.  Love those single-accumulator architectures with 256bytes or less of "special" RAM.   Not.  Gimme my AVR-DA!)

 

You should attack the ARM chips.  The instruction format is ugly, but there's a shortage of people willing to deal with it in assembler...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

What 8051 assembler program are you using?

SDCC includes an assembler.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:

Love those single-accumulator architectures with 256bytes or less of "special" RAM.   Not.

Hey, don't diss the 6502/6510.  While I can't compete with the stories from the really old guys of using punch cards, I learned "MCS6510" assembler from the C64 Programmer's Reference Guide.  I had no editor & assembler, so the first assembler program I wrote by looking up the instruction coding, and converted to decimal.  Then I wrote a BASIC program with a data section with the sequence of bytes to write to memory (POKE), then jump to the code with the SYS command.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

Last Edited: Sat. Jul 4, 2020 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really like the 51 structure, and intel's datasheets (I learned 8051 from Philips (now NXP) but the same thing).

And where I need ADC's I used siemens 80535 chips. 

 

The good thing is that you know what to expect, perhaps there are something extra but all the basics (most of the time :) I have used some cheap philips OTP's that didn't have a HW mul/div.) 

 

Like the 32 registers will always be placed at the first RAM addresses. Which the AVR copied.

Newer AVR's don't have this so some old code don't work on these chips.   

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
I had no editor & assembler, so the first assembler program I wrote by looking up the instruction coding, and converted to decimal.  Then I wrote a BASIC program with a data section with the sequence of bytes to write to memory (POKE), then jump to the code with the SYS command.

That's how I got started on the 6809.  Hand assembling programs directly into hex from memory onto foolscap.  Often during a boring English class.  When I finally started using an editor/assembler/debugger, it was an unaccustomed luxury!

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]