| home / infca / pic452 (navigation links) | "Deixar una cosa per a demà és deixar-la per sempre més".
Josep Pla |
| ADC | ICSP | My LVP | MPLAB | Forums | Programadors | FORTH | Dubtes | Links | End |
This powerful 10 MIPS (100 nanosecond instruction execution)
yet easy-to-program (only 77 single word instructions)
CMOS FLASH-based 8-bit microcontroller
packs Microchip's powerful PIC architecture
into an 40- or 44-pin package
and is upwards compatible with the PIC16C5X, PIC12CXXX, PIC16CXX and PIC17CXX devices
and thus providing a seamless migration path of software code
to higher levels of hardware integration.
The PIC18F452 features a 'C' compiler friendly development environment,
256 bytes of EEPROM, Self-programming, an ICD,
2 capture/compare/PWM functions,
8 channels of 10-bit Analog-to-Digital (A/D) converter,
the synchronous serial port can be configured as either
3-wire Serial Peripheral Interface (SPIT)
or the 2-wire Inter-Integrated Circuit (ICT) bus
and Addressable Universal Asynchronous Receiver Transmitter (AUSART).
All of these features make it ideal for
manufacturing equipment, instrumentation and monitoring, data acquisition,
power conditioning, environmental monitoring, telecom
and consumer audio/video applications.
(April 2008) The PIC18F452 its obsolete. There is a very good 16F guide here and the 16F877 is pin compatible. Better use 18F4620 .
| Registre | Funció | Detalls |
|---|---|---|
| WREG | working register | |
| INTCON | control d'interrupcions | 0=disabled, 1 = enabled (see INTCON) |
| T1CON | control del timer 1 | load preset value (?) |
| TMR1H&L | (?) | |
| WDTCON | watch dog control | (?) |
| PORTB | reads the pin levels / write to the port latch | input/output |
| LATB | output latch | output |
| TRISB | data direction | 1=input, 0=output |
Each port has three registers for its operation. These registers are:
Reading the PORTx register reads the status of the pins, whereas writing to it will write to the port latch.
PORTA is a 7-bit wide, bi-directional port.
PORTB is an 8-bit wide, bi-directional port.
PORTC is an 8-bit wide, bi-directional port.
PORTD is an 8-bit wide, bi-directional port.
PORTE is a 3-bit wide, bi-directional port.
| Operating frequency | DC-40 MHz |
|---|---|
| Program memory (bytes) | 32 K (0..0x7FFF) |
| Data memory (bytes) | 1536 (0..0x5FF) |
| Data EEPROM memory (bytes) | 256 |
| I/O ports | A thru E (5) |
| Timers | 4 |
| 10-bit AtoD module | 8 input channels |
| Instruction set | 75 instructions |
Registers - program counter (PCL), STATUS, working (WREG), bank select register (BSR), mapped ports (TRISx), interrupt control (INTCON), file select (FSR#), special function (SFR).
| The Special Function Registers (SFRs) are registers used by the CPU and Peripheral Modules for controlling the desired operation of the device. These registers are implemented as static RAM, from 0xF80 thru 0xFFF (up to 128SFRs). |
|
|
The PIC18FXX2 can be operated in eight different Oscillator modes. The user can program three configuration bits (FOSC2, FOSC1, and FOSC0) to select one of these eight modes:
In XT, LP, HS or HS+PLL Oscillator modes, a crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to establish oscillation.
Atenció : seleccionem XT mode, 4 MHz crystal, C1 = C2 = 22 pF.
For RCIO oscilator configuration, the values are :
|
|
There are several features intended to maximize system reliability, minimize cost through elimination of external components, provide power saving Operating modes and offer code protection.
The configuration bits can be programmed (read as '0'), or left unprogrammed (read as '1'), to select various device configurations. These bits are mapped starting at program memory location 300000h. The user will note that address 300000h is beyond the user program memory space. In fact, it belongs to the configuration memory space (300000h - 3FFFFFh), which can only be accessed using Table Reads and Table Writes.
The sequence of events for programming configuration registers is:
[*] Default (unprogrammed) value := 0b--1- -111 ;
MPLAB IDE v8.0 : Configure + Configuration bits.
En ensamblador :
| Mnemonic | Meaning |
|---|---|
| BCF | bit Clear |
| BSF | bit Set |
| BTFSC | bit test, skip if Clear |
| BTFSS | bit test, skip if Set |
| CLRF | clear f |
| DECF | decrement f |
| DECFSZ | decrement, skip is zero |
| INCF | increment f |
| MOVF | move f |
| MOVFF | move fs to fd |
| MOVLW | move literal to register W |
| MOVWF | move WREG to f |
| SETF | set f |
Timer0 can operate as a timer or as a counter.
The TMR0 interrupt is generated
when the TMR0 register overflows from FFh to 00h in 8-bit mode,
or FFFFh to 0000h in 16-bit mode.
Timer mode is selected by clearing the T0CS bit.
In Timer mode, the Timer0 module will increment
every instruction cycle (without prescaler).
Counter mode is selected by setting the T0CS bit.
In Counter mode, Timer0 will increment,
either on every rising or falling edge of pin RA4/T0CKI.
Registers associated with Timer0 :
Una configuració mínima de HW és doncs :
|
[Bibl-3], chapter 17.
A/D conversion code
sample.
Al utilizar un periférico, no importa de que microcontrolador,
lo recomendable es atenerse a las banderas de estado o status.
En el registro ADCON0, el bit 2 es llamado "GO/-DONE".
Se usa para arrancar, pero también indica el estado.
Escribes un uno para arrancar la conversión,
y mientras permanece en uno, el convertidor está trabajando.
Al momento que la conversión termina, el bit "GO/-DONE" cae a cero.
Eso está en la hoja de datos del microcontrolador.
Para no desperdiciar ciclos,
es preferible usar una rutina de interrupción de fin de conversión.
The PIC18FXX2 oscillator design requires the use of a parallel cut crystal.
Sample code is in the 18F452 datasheet.
After battling with a 18F452 for ages, trying to get it to run at 40 MHz using the PLL_HS with a 10 MHz resinator, all I could get it to do was oscilate at 10 MHz. The solution is to add a 4M7 resistor across the osc1 and osc2 pins. Works like a charm!
Each ADC needs a reference voltage which defines 100% or 0xFF (for a 8-Bit ADC). In the case of your PIC there is a matrix in the datasheet on page 184, chapter 17.
| pin name | pin | type | description |
|---|---|---|---|
| MCLR/Vpp/RE3 | 1 | power | programming enable |
| Vdd | 11, 32 | power | power supply |
| Vss | 12, 31 | power | ground |
| RB5/PGM | 38 | input | low voltage input |
| RB6/PGC | 39 | input | serial clock |
| RB7/PGD | 40 | input | serial data |
In this mode, the RB5/PGM pin is dedicated to the programming function and ceases to be a general purpose I/O pin. The trade off is, if LVP is enabled, PGM pin cannot be used as I/O anymore. During programming, VDD is applied to the MCLR/VPP pin. To enter Programming mode, VDD must be applied to the RB5/PGM, provided the LVP bit is set. While in low voltage ICSP mode, the RB5 (PGM, pin 38) pin can no longer be used as a general purpose I/O pin, and should be held low during normal operation to protect against inadvertent ICSP mode entry.
Vpp = High voltage ICSP programming enable pin.
MCLR = Master Clear (Reset) input.
This pin is an active low RESET to the device.
The LVP bit defaults to a ('1') from the factory.
19.8, Low Voltage ICSP Programming, DS39564C-page 210 [212/332]
PGM = Low Voltage ICSP programming enable pin.
PGC = In-Circuit Debugger and ICSP programming clock pin.
PGD = In-Circuit Debugger and ICSP programming data pin.
|
For reading and writing program memory using this adapter, you also have to apply power to the PIC (+5V at Vdd) and tie MCLR to high level (Vdd); Microchip suggests to use a resistor for MCLR because of latch-up risk. An oscillator circuit doesn't have to be connected. Of course, connect the three lines PGD, PGC and PGM to this adapter, too. Since you use Low Voltage Programming-mode, pin PGM (38 = RB5/PGM) is not usable for I/O. If you programm a PIC in this manner, always ensure PGM is pulled low in the application (e.g. by adding 10K to ground) even if the schematics look different. Otherwise the PIC might enter programming mode instead of normal working mode. LVP-mode is enabled by high level on pin PGM. The second 10k resistor at PGM pulls this pin to ground if no PC is connected and thus safely prevents the PIC from entering LVP-mode. Don't high voltages on RS-232 harm the PIC? All the PIC's I/O-pins are protected against electric discharge by internal diodes to Vss and Vdd (see datasheet!). With a resistor limiting the pin current, all voltages will get clamped between 0V and 5V. For programming, you can use ICProg from Bonny Gijzen. Configure as JDM-type-programmer ... (JDM homepage) |
D-9 :
PIC :
| ||||||||||||||
|
Before building this programmer, be sure that your serial port (RS232) have at least 11 Volts. needed to program the Series "C" (12C50X, 16C84, etc). With 9.5 volts you will be able to program only a few microcontrollers. If you get an error while programming, change the 1mF capacitor to 0,47mF. Doesn't work? Maybe the voltage at the port is not good enough. Put a 10mF capacitor between the VDD and GND. | ||||||||||||||
Melting mr's Lothar design (up right) with mr's Jose Pino design (up left), here you have a working LVP for 18F452 ! Que fa el IC-prog ? What does IC-prog ?
Posa TxD (pin 3/9 x PGM and "delayed" x MCLR) a "ON".
Atenció : per programar el PIC, s'ha de
Per ejecutar el PIC, aquestes mesures s'han de invertir, es clar ... Mesures del RS-232 :
Poso IC-prog a P4/RAP => "File + Open" tanca el programa !? c:> ic-prog.exe -lFILENAME.HEX -p | |||||||||||||||
Símptomes : "Privileged instruction", "Access violation ...",
P4 - mola {21-09-2008} !
Install :
New Project :
A more interesting one :
A simple program fragment that reads a string of fixed characters is:
The data strings are stored in memory like this :
An improved sample, from MicroChip :
If the oscillators running you can't program a PIC;
you need to switch it to programming mode
BEFORE the oscillator can start up.
When doing ICSP this can often be difficult,
usually both your circuit and programmer
need to be specially designed for the purpose.
Nigel Goodwin
Llum verd = -8,5 volts, llum vermell = +8,9 volts.
Conclusió : mesurar RS-232 a diversos PCs.
Verify failed at 0x000
Vih = Vdd + 4v ...
[1] + cheap ICSP programmer by Squibcakes {Schematics}
I have used it on 16F84, 16F62X, 16F87X chips without problems. To make it:
[2] Microcontrollers + "PIC Programmer ?" (autor = mitesh, 12/Feb/2008)
[3] Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers. "cant program 18F452 using LVP"
One easy way is to do it with Forth !
FlashForth is a a Forth OS that runs on the PIC18F452.
See
http://flashforth.sourceforge.net/
After you have programmed the FF kernel to the PIC, you can via the
serial port expirement with how the PIC works.
Here is the Forth source code of how to read the AD converter on the PIC18F452.
Now with the command " 1 ad @
The converted value 3ff is returned on the parameter stack and printed with "." .
[2] Microchip Application Notes, 8-bit PIC microcontrollers Application Notes
[3] Microchip PIC18Fxx2 Datasheet {39564c.pdf}
[4] MPLAB_IDE_v6.xx.Quick_Start_Guide_pic-guide-51281c.pdf
[5] MPLAB_IDE_Users_Guide_51519a.pdf [url]
[6] MPASM_Users_Guide_33014J.pdf [url]
[7] PICkit Programmer Debugger User's Guide - ICSP at Chapter 3 [*****]
SAG 1-st email =>
"PICSTART plus Development System", code "DV003001". Tag = 136,24 €
DV164120 - PICkit 2 Starter Kit = 34 €
PICkit 2 Microcontroller Programmer and a PICkit 2 Low Pin Count Demo Board containing a PIC16F690 PDIP.
PG164120 - PICkit 2 Microcontroller Programmer = 24 €
SAG 2-nd email =>
You need to buy the following items
along with pickit2 programmer kit (PG164120).
While using 40pin universal programming module, removal of resistor R1 is required to prevent VPP errors (from AC162049).
Total = 57,89 €
Main differences between PIC 18F452 and 16F877 - note that both are 8 bit microcontrollers.
Conectrol, Jorge Juan 57, 91.566.15.20
Velleman VM134 (50€ o
47€)
+ PS1508 (15v, 0,8A)
specs.
|
|
|
|
Updated : 24/09/2008.
|
|