Posts

Advanced PIC18 Projects—SD Card Projects:Using the Card Filing System

Image
PROJECT 7.3—Using the Card Filing System The hardware of this project is the same as for Project 7.1 (i.e., as shown in Figure 7.8). In this project, a file called MYFILE55.TXT is created on the SD card. String “This is MYFILE.TXT” is written to the file initially. Then the string “This is the added data.. .” is appended to the file. The program then reads the contents of the file and sends the string “This is MYFILE.TXT. This is the added data.. .” to the UART, enabling the data to be displayed on the PC screen when HyperTerminal is run. The program listing of the project is given in Figure 7.12 (program SD3.C). At the beginning of the program the UART is initialized to 2400 baud. Then the SPI bus and the FAT file system are initialized as required by the library. The program then creates file MYFILE55.TXT by calling library function Mmc_Fat_Assign with the arguments as the filename and the creation flag 0x80, which tells the function to create a new file if the file doe...

Advanced PIC18 Projects—CAN Bus Projects:PIC18F258 Microcontroller

Image
PIC18F258 Microcontroller Later in this chapter the PIC18F258 microcontroller is used in a CAN bus–based project. This section describes this microcontroller and its operating principles with respect to its built-in CAN bus. The principles here are in general applicable to other PIC microcontrollers with CAN modules. The PIC18F258 is a high performance 8-bit microcontroller with integrated CAN module. The device has the following features: • 32K flash program memory • 1536 bytes RAM data memory • 256 bytes EEPROM memory • 22 I/O ports • 5-channel 10-bit A/D converters • Three timers/counters • Three external interrupt pins • High-current (25mA) sink/source • Capture/compare/PWM module • SPI/I2C module • CAN 2.0A/B module • Power-on reset and power-on timer • Watchdog timer • Priority level interrupts • DC to 40MHz clock input • 8 x 8 hardware multiplier • Wide operating voltage (2.0V to 5.5V) • Power-saving sleep mode The features of the PIC18F...

Simple PIC18 Projects

In this chapter we will look at the design of simple PIC18 microcontroller-based projects, with the idea of becoming familiar with basic interfacing techniques and learning how to use the various microcontroller peripheral registers. We will look at the design of projects using LEDs, push-button switches, keyboards, LED arrays, sound devices, and so on, and we will develop programs in C language using the mikroC compiler. The hardware is designed on a low-cost breadboard, but development kits such as BIGPIC4 can be used for these projects. We will start with very simple projects and proceed to more complex ones. It is recommended that the reader moves through the projects in their given order. The following are provided for each project: • Description of the program • Description of the hardware • Circuit diagram • Algorithm description (in PDL) • Program listing • Suggestions for further development The program’s algorithm can be described in a variety of g...

Multi-Tasking and Real-Time Operating Systems:Voltmeter with RS232 Serial Output

Image
PROJECT 10.3—Voltmeter with RS232 Serial Output In this RTOS project, which is more complex than the preceding ones, the voltage is read using an A/D converter and then sent over the serial port to a PC. The project consists of three tasks: Live, Get_voltage, and To_RS232. • Task Live runs every 200ms and flashes an LED connected to port RD7 of the microcontroller to indicate that the system is working. • Task Get_voltage reads channel 0 of the A/D converter where the voltage to be measured is connected. The read value is formatted and then stored in a variable. This task runs every two seconds. • Task To_RS232 reads the formatted voltage and sends it over the RS232 line to a PC every second. Figure 10.12 shows the block diagram of the project. The circuit diagram is given in Figure 10.13. A PIC18F8520-type microcontroller with a 10MHz crystal is used in this project (though any PIC18F-series microcontroller can be used). The voltage to be measured is connected to analog port...

Multi-Tasking and Real-Time Operating Systems:Random Number Generator

Image
PROJECT 10.2—Random Number Generator In this slightly more complex RTOS project, a random number between 0 and 255 is generated. Eight LEDs are connected to PORTB of a PIC18F452 microcontroller. In addition, a push-button switch is connected to bit 0 of PORTD (RD0), and an LED is connected to bit 7 of PORTD (RD7). Three tasks are used in this project: Live, Generator, and Display. • Task Live runs every 200ms and flashes the LED on port pin RD7 to indicate that the system is working. • Task Generator increments a variable from 0 to 255 continuously and checks the status of the push-button switch. When the push-button switch is pressed, the value of the current count is sent to task Display using a messaging queue. • Task Display reads the number from the message queue and sends the received byte to the LEDs connected to PORTB. Thus, the LEDs display a random pattern every time the push button is pressed. Figure 10.9 shows the project’s block diagram. The circuit diagram is ...

Multi-Tasking and Real-Time Operating Systems:CCS PIC C Compiler RTOS

Image
CCS PIC C Compiler RTOS The CCS PIC C compiler is one of the popular C compilers for the PIC16 and PIC18 series of microcontrollers. In addition to their PIC compilers, Customer Computer Services offers PIC in-circuit emulators, simulators, microcontroller programmers, and various development kits. The syntax of the CCS C language is slightly different from that of the mikroC language, but readers who are familiar with mikroC should find CCS C easy to use. CCS C supports a rudimentary multi-tasking cooperative RTOS for the PIC18 series of microcontrollers that uses their PCW and PCWH compilers. This RTOS allows a PIC microcontroller to run tasks without using interrupts. When a task is scheduled to run, control of the processor is given to that task. When the task is complete or does not need the processor any more, control returns to a dispatch function, which gives control of the processor to the next scheduled task. Because the RTOS does not use interrupts and is not preemptive,...

Multi-Tasking and Real-Time Operating Systems:LEDs

Image
PROJECT 10.1—LEDs In the following simple RTOS-based project, four LEDs are connected to the lower half of PORTB of a PIC18F452-type microcontroller. The software consists of four tasks, where each task flashes an LED at a different rate: • Task 1, called task_B0, flashes the LED connected to port RB0 at a rate of 250ms. • Task 2, called task_B1, flashes the LED connected to port RB1 at a rate of 500ms. • Task 3, called task_B2, flashes the LED connected to port RB2 once a second. • Task 4, called task_B3, flashes the LED connected to port RB3 once every two seconds. Figure 10.7 shows the circuit diagram of the project. A 4MHz crystal is used as the clock. PORTB pins RB0–RB3 are connected to the LEDs through current limiting resistors. The software is based on the CCS C compiler, and the program listing (RTOS1.C) is given in Figure 10.8. The main program is at the end of the program, and inside the main program PORTB pins are declared as outputs and RTOS is started by c...