ASSEMBLY LANGUAGE If you develop your code for a C compiler or Basic compiler, the compiler will convert your program into assembly language and then. And 40-pin P/C® MCUs 2-line, 20-char LCD Module 9-pin Serial Port Sample Programs Full Schematic Diagram Pricing from $79.95 to $349.95 PICPROTO™.
Hi all, sorry I didn't get back sooner just been busy with work. I have set the internal oscillator using the SCS bit. I forgot to put the SPBRH value in but now its in its kind of working I've tried different characters and this is what I'm getting:1) The number '9' (00111001) gave 5 9's then it changed to 'N' (01001110) which I noticed is '9' shifted right 2 bits2) The letter 'F' (01000110) gave 5 F's then stopped, restarting new connection gave all F's3) The letter 'G' (01000111) gave a zero with a caret (^)4) The letter 'X' (01011000) gave 5 a's then all X'sAnyone know why this is happening. The noise on the waveform is not that bad.
Hi all, sorry I didn't get back sooner just been busy with work. I have set the internal oscillator using the SCS bit. I forgot to put the SPBRH value in but now its in its kind of working I've tried different characters and this is what I'm getting:1) The number '9' (00111001) gave 5 9's then it changed to 'N' (01001110) which I noticed is '9' shifted right 2 bits2) The letter 'F' (01000110) gave 5 F's then stopped, restarting new connection gave all F's3) The letter 'G' (01000111) gave a zero with a caret (^)4) The letter 'X' (01011000) gave 5 a's then all X'sAnyone know why this is happening. The noise on the waveform is not that bad. Click to expand.Not all baud rates are possible see manual.Always use Interrupts to collect data. Let me know if a sample program is needed.Below is a simple example to calculate settings for baud rates but again check manual.You are able to fiddle the 8MHz internal clock to adjust baud rate ( see manual).Picbuster#define XTALFREQ 8000000#define FOSC 8000000L#define NINE 0 /. Use 9bit communication?
FALSE=8bit./#define BAUD 4800#define DIVIDER ((int)(FOSC/(16UL. BAUD) -1))#define HIGHSPEED 1#if NINE 1#define NINEBITS 0x40#else#define NINEBITS 0#endif#if HIGHSPEED 1#define SPEED 0x4#else#define SPEED 0#endif#define RXPIN TRISB5 //pin 12#define TXPIN TRISB7 //pin 10/. Serial initialization./#define initcomms RXPIN = 1; TXPIN = 1; SPBRG = DIVIDER; RCSTA = (NINEBITS 0x90); TXSTA = (SPEED NINEBITS 0x20).
Setting up the PIC MicrocontrollerThe following programs are examples that I use for teaching the programmingof 8-bit PIC microcontrollers. A good reference is the book 'Designing EmbeddedSystems with PIC microcontrollers: Principles and Applications'by Tim Wilmshurst. The datasheet for the PIC is also a good referencefor information on the bits for each memory address register in the chip.The method we use is to program the PIC chip using the PICKit2 in assemblylanguage. The PICKit2 is relatively inexpensive and services a largevariety of PIC microcontrollers. We usually start with the PIC16F690microcontroller since it has just about everything we need and hasa small pin count (20). Placing the PIC16F690 in a breadboard, We use the PICKit2 'only'and connect our own 6 wires from the PICKit2 to the microcontroller as shown inthe diagram.We carry out thefollowing procedure to test our system. Programming is done using the MPLAB (free download)software from microchip in assembly.
First program the PIC chip with the program,which puts 5 volts then 0 volts on pin #16 (C0). Check the output of pin #16 with an oscilloscope. One should see a 5 volt outputthat lasts 1 micro-sec (for a 4 MHz clock), and 0 volts that lasts for3 micro-sec. If this works, then we know that we have set up the programmer and chipcorrectly. Next we check the serial transfer, since we will want to receive and save data wesend from the microcontroller.
As a first check we program the code,which sends the same number via serial at 9600 BAUD. To check if the serial output is working, we connect the oscilloscopeto the TX pin (#10 for PIC16F690). The output for a zero in the binary number should be 5 volts lasting1 micro-sec (for 9600 BAUD). The output for a one in the binary number should be 0 volts lastingfor 1 micro-sec (for 9600 BAUD). There will also be a start and stop bit, so the completesignal will be 10 bits long.
If the TX pin is producing the correct output, there are two ways that we canread the serial data with the PC: using a TTL-232R-5V cable to usb, or usinga MAX232 chip to a serial port. The former method is simple and easy to use. USB input to PC: The easiest way to transfer data from the PIC to the PC is to use aTTL to USB cable: TTL-232R-5V (straight connector) or TTL-232R-5V-WE (wire ends)made by FTDI. The cable has 6 leads, 4 of which are connected directly to thePIC pins.
Seefor a circuit diagram of the connections. SERIAL PORT input to PC: If one wants to input to a serial port, then the MAX232 chip provides theappropriate voltage shifting for the port. The MAX232 chip will shift 5 volts to +8 volts and 0volts to -8 volts for input to the serial port. See(compliments of www.SoDoItYourself.com) forthe circuit diagram to connect the PIC to the serial port. To check the circuit,we read the output of the MAX232 chip with the oscilloscopeto insure that the correct +/- 8 volts represents the binary number.
Finally, the asynchronous serial output to the PC is read in the Linux operating system with one ofthe C programs listed below (Reading the Asynchronous Serial Output).Once the correct binary number is reproduced on thePC monitor, we can start our projects. Since in this test we are sending the samebinary number every time, we sometimes get framing errors. As another check of the serial transfer, we program the microcontrollerwith the program,which increments the binary number by one and sends it via serial to thePC. Consecutive numbers should be output on the PC monitor. See for our in-circuit programmingsetup on a breadboard.
See for a picture of ourbreadboard. A 20 Mhz resonator has been connected to the chip in the picture.Sample Programs for the PIC Microcontroller.is an assembly code which reads the timer and sends the data to the PC viaserial.
The code has a nice interrupt routine that increments registerswhen timer0 overflows. The full clock uses 4 registers.is an assembly code which we use for laser (or photo) gate timing. The programwaits till pin 11 goes low, takes a time stamp, and sends the 4 timerbytes via serial to a PC.
It then waits till pin 11goes high, takes a time stamp and sends the 4 timer bytes via serial to a PC.The loop is repeated forever. This program was developed by 'CJ' Beccarellias part of his senior project.is an assembly code which fast analog to digital is done 80 times with the valuesstored in memory.
The data is then transfered via serial to the PC. The config lineincludes the external20 MHz resonator (HSOSC), and serial is transfered at 115.2 KBaud. 10 bit A-to-Dsampling can be done at 300KHz with this program. This program was written byMichael Mansell as part of his senior project.Reading the Asynchronous Serial Output from the Chip via the PC Serial Port and USB portAn excellent web site for reading and writting to the serial and parallelport is 'www.beyondlogic.com'.
Below we list a sample program, whichruns in Linux, to read the serial port.: This program is written in Cand runs in Linux. It reads the serial port 24 times in succession andprints the bytes to the screen. We just use it as a test to see ifthe PIC chip is transmitting serial data correctly. The serial data can also be read via a USB port. The program: is written in Cand runs in Linux.
We use a serial-USBadapter for which Ubuntu has a driver. Once the USB jack is plugged in,a device driver 'ttyUSB0' is set up.Timing on the PC via Parallel PortOne can do fairly accurate timing for TTL input using the parallel port.Below, we list some codes that we use (or have used) in our classroom forphotogate timing.: This program is written in C and runsin Linux for our pendulum experiment. It checks the parallel port for achange on pin 10. When a change occurs, a time stamp is obtained usinga call to rdtsc.: This program is written inC and runs in Linux for our atwood machine experiment. It checks the parallelport for a change on pin 10 on the parallel port. When a change occurs, atime stamp is obtained using a call to rdtsc.
The data can be graphed onthe monitor via the X11 library. To compile use gcc -lm -lX11 atwoodxpar.cThere are translations of this page in Romanian, Estonian, Latvian, Polish, Hungarian,Macedonian, Bulgarian, and Finnish. Links to these translations have beenremoved.