Active4 years, 8 months ago
Best 8051 Compiler
$begingroup$I have a counter which counts number the of interrupts at pin 3.2 in 8051. I'm not sure about the implementation. So far I could count the number of interrupts but I couldn't send the integer value in UART. It's giving me the ASCII values actually. I know that
SBUF = 'A';
will send ASCII value of 'A'. How to send the integers ? This is my code that I've been trying to make it work. Examine 8051 projects and learn the tricks. Here are some test projects suitable for any 8051 microcontroller to show how to use Turbo51. They can also be used to quickly see the generated code. The assembler files can also serve as 8051 code examples. This is a '8051 hello world' example. This is a simple example. This manual is aimed at users of the TASKING C 8051 Cross-Compiler. It assumes that you are familiar with the C language. MANUAL STRUCTURE Related Publications Conventions Used In This Manual Chapters 1. Software Installation Describes the installation of the C Cross-Compiler for the 8051.
- Serial communication using UART or USART of a microcontroller 8051 AVR PIC, software implementation of half-duplex UART and MAX232 interfacing with microcontrollers 8051 AVR PIC.
- Software UART for PIC16F84A microcontroller with CCS C compiler The microcontroller PIC16F84A has no hardware UART module, but we can use software UART to send/receive data to/from the PC via RS232 cable (COM port).
- Paul's 8051 Tools, Projects and Free Code. AS31 Assembler & SDCC C Compiler AS31 is a free 8051 assembler originally written. AS31 is also Free Software.
d-coderd-coder
$endgroup$1 Answer
$begingroup$The existing call to
sprintf
looks like the right way to do the number formatting, since stdio.h seems to be available. The bufffer buf
should contain '0', '1', '2', etc. But it's unclear whether or not that is happening..A good first diagnostic is to add a banner message, to test whether the 8051 serial link is working at all. Maybe the serial port was not being initialized? Maybe the terminal software is configured to the wrong baud rate? Or maybe the serial cable itself is defective?
As a second diagnostic, try printing a constant, known number value. Contoh soal toefl itp dan pembahasannya pdf to jpg free. Suggested code edits below:
With these edits, every time the 8051 is reset, its firmware should send:
If you don't see these either of two lines appear on your terminal window, there's something wrong with the serial link.
- reset the 8051 but keep its power on. Maybe the clock isn't stable when first powered up?
- the terminal software is configured to the wrong baud rate?
- the serial cable itself is defective?
If you see only the first line but not the
231
, then the serial port is working but for some reason the sprintf(buf, '%d', c)
isn't formatting the number.- check the listing, is buf[] declared in the right memory address space?
Further diagnostics: See if your C compiler generates an assembly listing of the actual 8051 instuctions, and a map file showing where all of the functions and variables are. The 8051 has several address spaces, so C compilers that target 8051 have extensions to direct which address space each variable belongs in. Also, check whether the linker is targeting the correct 8051 variant. This microcontroller architecture has been around for decades, and there are lots of variations. If the compiler is building code for a 65K chip and putting data in external memory (xram), but then the target chip is a smaller 2k chip with no xram, that's not going to work.
About the interrupt handler. Long-term it would be better practice to avoid sending serial port strings inside the interrupt handler, because interrupt service routines are usually meant to quickly respond to a hardware condition and return to the foreground task as quickly as possible. Sending a character over the serial port is relatively slow, so the 8051 will be spending a lot of time in the interrupt. It's pretty common for an interrupt routine to just capture the hardware registers and set a global flag, for the main while loop to deal with it later. Also, serial port routines are sometimes implemented using interrupts, so in that kind of system it's important to avoid using the serial port from within another interrupt handler, because the processor is already handling one interrupt and can't manage another until the first one RETI returns and the 8051 exits interrupt mode. But since the main task is an empty loop and the serial routine isn't using interrupts, there should be no conflict in this case.
MarkUMarkU7,22911 gold badge1212 silver badges2323 bronze badges
$endgroup$Not the answer you're looking for? Browse other questions tagged 8051 or ask your own question.
Viewed 4k times
I'm a bit hardly to get string from Interrupt 4 function. but when I try to get single character and shown in the LCD 2*16 it's works well. but when I try to get the string from 'dot[i]' variable, for showing to the LCD, it doesn't work.
this my code :
for the compiler I using Keil v4
Adhy
AdhyAdhy
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.