You are on page 1of 12

1

PALABRA DE CONFIGURACIN 18F4550:



1.00 PLL1 No PLL PreScaler Divide By 1
1.00 PLL2 Divide By 2(8MHz oscillator input)
1.00 PLL3 Divide By 3(12MHz oscillator input)
1.00 PLL4 Divide By 4(16MHz oscillator input)
1.00 PLL5 Divide By 5(20MHz oscillator input)
1.00 PLL6 Divide By 6(24MHz oscillator input)
1.00 PLL10 Divide By 10(40MHz oscillator input)
1.00 PLL12 Divide By 12(48MHz oscillator input)

1.03 CPUDIV1 No System Clock Postscaler
1.03 CPUDIV2 System Clock by 2
1.03 CPUDIV3 System Clock by 3
1.03 CPUDIV4 System Clock by 4

1.05 NOUSBDIV USB clock source comes from primary oscillator
1.05 USBDIV USB clock source comes from PLL divide by 2

1.08 XT Crystal osc <= 4MHz for PCM/PCH , 3mhz to 10 MHz for PCD
1.08 XTPLL Crystal/Resonator with PLL enabled
1.08 EC_IO External clock
1.08 EC External clock with CLKOUT
1.08 ECPLL_IO External Clock with PLL enabled, I/O on RA6
1.08 ECPLL External Clock with PLL enabled and Fosc/4 on RA6
1.08 INTRC_IO Internal RC Osc, no CLKOUT
1.08 INTRC Internal RC Osc
1.08 INTXT Internal Oscillator, XT used by USB
1.08 INTHS Internal Oscillator, HS used by USB
1.08 HS High speed Osc (> 4MHz for PCM/PCH) (>10MHz for PCD)
1.08 HSPLL High Speed Crystal/Resonator with PLL enabled






4 MHz


48 MHz




4 MHz

2


USDIV: USDIV=1. La seal de reloj pasa por el PLL Prescaler
PLL1: PLLDIV=000 (%1). Entrada PLL Prescaler (4 MHz). Salida PLL Prescaler (4MHz)
CPUDIV1: CPUDIV=00 (%1). Se mantienen los 4 MHz para temporizar el sistema (CPU)


1.14 NOFCMEN Fail-safe clock monitor disabled
1.14 FCMEN Fail-safe clock monitor enabled

1.15 NOIESO Internal External Switch Over mode disabled
1.15 IESO Internal External Switch Over mode enabled

2.00 PUT Power Up Timer
2.00 NOPUT No Power Up Timer

2.01 NOBROWNOUT No brownout reset
2.01 BROWNOUT_SW Brownout controlled by configuration bit in special file register
2.01 BROWNOUT_NOSL Brownout enabled during operation, disabled during SLEEP
2.01 BROWNOUT Reset when brownout detected

2.03 BORV45 Brownout reset at 4.5V
2.03 BORV43 Brownout reset at 4.3V
2.03 BORV27 Brownout reset at 2.7V
2.03 BORV20 Brownout reset at 2.0V

2.05 NOVREGEN USB voltage regulator disabled
2.05 VREGEN USB voltage regulator enabled

2.08 NOWDT No Watch Dog Timer
2.08 WDT Watch Dog Timer

2.09 WDT1 Watch Dog Timer uses 1:1 Postscale
2.09 WDT2 Watch Dog Timer uses 1:2 Postscale
2.09 WDT4 Watch Dog Timer uses 1:4 Postscale
2.09 WDT8 Watch Dog Timer uses 1:8 Postscale
2.09 WDT16 Watch Dog Timer uses 1:16 Postscale
2.09 WDT32 Watch Dog Timer uses 1:32 Postscale
2.09 WDT64 Watch Dog Timer uses 1:64 Postscale
2.09 WDT128 Watch Dog Timer uses 1:128 Postscale
2.09 WDT256 Watch Dog Timer uses 1:256 Postscale
2.09 WDT512 Watch Dog Timer uses 1:512 Postscale
2.09 WDT1024 Watch Dog Timer uses 1:1024 Postscale
2.09 WDT2048 Watch Dog Timer uses 1:2048 Postscale
2.09 WDT4096 Watch Dog Timer uses 1:4096 Postscale
2.09 WDT8192 Watch Dog Timer uses 1:8192 Postscale
2.09 WDT16384 Watch Dog Timer uses 1:16384 Postscale
2.09 WDT32768 Watch Dog Timer uses 1:32768 Postscale
3


3.08 CCP2B3 CCP2 input/output multiplexed with RB3
3.08 CCP2C1 CCP2 input/output multiplexed with RC1

3.09 NOPBADEN PORTB pins are configured as digital I/O on RESET
3.09 PBADEN PORTB pins are configured as analog input channels on RESET

3.10 NOLPT1OSC Timer1 configured for higher power operation
3.10 LPT1OSC Timer1 configured for low-power operation

3.15 NOMCLR Master Clear pin used for I/O
3.15 MCLR Master Clear pin enabled

4.00 NOSTVREN Stack full/underflow will not cause reset
4.00 STVREN Stack full/underflow will cause reset

4.02 NOLVP No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
4.02 LVP Low Voltage Programming on B3(PIC16) or B5(PIC18)

4.05 ICSP1 ICD uses PGC1/PGD1 pins
4.05 ICSP2 ICD uses PGC2/PGD2 pins

4.06 NOXINST Extended set extension and Indexed Addressing mode disabled (Legacy mode)
4.06 XINST Extended set extension and Indexed Addressing mode enabled

4.07 DEBUG Debug mode for use with ICD
4.07 NODEBUG No Debug mode for ICD

5.00 PROTECT Code protected from reads
5.00 NOPROTECT Code not protected from reading

5.14 CPB Boot Block Code Protected
5.14 NOCPB No Boot Block code protection

5.15 CPD Data EEPROM Code Protected
5.15 NOCPD No EE protection

6.00 WRT Program Memory Write Protected
6.00 NOWRT Program memory not write protected

6.13 WRTC Configuration registers write protected
6.13 NOWRTC Configuration registers not write protected

6.14 WRTB Boot block write protected
6.14 NOWRTB Boot block not write protected

6.15 WRTD Data EEPROM write protected
4

6.15 NOWRTD Data EEPROM not write protected

7.00 EBTR Memory protected from table reads
7.00 NOEBTR Memory not protected from table reads

7.14 EBTRB Boot block protected from table reads
7.14 NOEBTRB Boot block not protected from table reads


PRCTICA Nro. 1: Encendido y apagado de un LED en RBO



/*---------------------------------------------------------------------------------------------*/
/* Ciclo de encendido (1s) y apagado (1s)de un LED conectado en RB0 */
/*---------------------------------------------------------------------------------------------*/
#include <18F4550.h>
#fuses PLL1,CPUDIV1,USBDIV,XT,NOFCMEN,NOIESO,PUT,NOBROWNOUT,NOWDT,CCP2C1
#fuses NOPBADEN,NOLPT1OSC,MCLR,STVREN,NOLVP,NOXINST,NODEBUG,NOPROTECT
#fuses NOCPB,NOCPD,NOWRT,NOWRTC,NOWRTB,NOWRTD,NOEBTR,NOEBTRB
#use delay (clock=4M)

void main()
{
5

while(TRUE)
{
output_bit(PIN_B0,1); // Enciende LED en RB0. Tb output_high(PIN_B0)
delay_ms(1000); // Retardo de 1000 ms
output_bit(PIN_B0,0); // Apaga LED en RB0
delay_ms(1000); // Retardo de 1000 ms
}
}


PRCTICA Nro. 2: Encendido y apagado de un LED en RBO



/*----------------------------------------------------------------------*/
/* Encendido y apagado de un led en RB2 con */
/* pulsadores en RB0 y RB1. */
/*----------------------------------------------------------------------*/
#include <18F4550.h>
#fuses PLL1,CPUDIV1,USBDIV,XT,NOFCMEN,NOIESO,PUT,NOBROWNOUT,NOWDT,CCP2C1
#fuses NOPBADEN,NOLPT1OSC,MCLR,STVREN,NOLVP,NOXINST,NODEBUG,NOPROTECT
#fuses NOCPB,NOCPD,NOWRT,NOWRTC,NOWRTB,NOWRTD,NOEBTR,NOEBTRB
#use delay (clock=4M)

void rebote()
{
unsigned int16 j = 0;
int1 save, current;
save = 0;
6

for(j = 0; j < 400; j++)
{
if((current == input_state(PIN_B0)) != save || (current == input_state(PIN_B1)) != save)
j = 0;
save = current;
}
}

void main()
{
port_b_pullups (TRUE);
output_low(PIN_B2);
while(TRUE)
{
if(!input(PIN_B0))
{
rebote();
output_toggle(PIN_B2);
}
if(!input(PIN_B1))
{
rebote();
output_toggle(PIN_B2);
}
}
}



7

PRCTICA Nro. 3: Conversor A/D

/*--------------------------------------------------------------------------*/
/* EL RESULTADO DE LA CONVERSIN A/D DEL CANAL0 */
/* SE MUESTRA EN EL PUERTO B Y PUERTO C */
/*--------------------------------------------------------------------------*/
#include <18F4550.h>
#fuses PLL1,CPUDIV1,USBDIV,XT,NOFCMEN,NOIESO,PUT,NOBROWNOUT,NOWDT,CCP2C1
#fuses NOPBADEN,NOLPT1OSC,MCLR,STVREN,NOLVP,NOXINST,NODEBUG,NOPROTECT
#fuses NOCPB,NOCPD,NOWRT,NOWRTC,NOWRTB,NOWRTD,NOEBTR,NOEBTRB
#device ADC=10
#use delay (clock=4M)
/*----------------------------------------------------------------------*/
void main()
{
int16 adcValue;
int8 i;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
do
{
set_adc_channel(0);
delay_us(20); // Retardo para carga del condensador de muestreo

adcValue=read_adc(); // Lee el resultado de la conversin
output_b(adcValue); // Parte baja de la conversin a PORTB
for (i=0;i<8;i++)
rotate_right(&adcValue,2); // shift_right(&adcValue,2,1);
output_c(adcValue); // Parte alta de la conversin a PORTC
8

} while (TRUE);
}


PRCTICA Nro. 4: Conmutador, usando funcin rebote()


/*----------------------------------------------------------------------*/
/* Temperatura actual por canal 0 y LM35 */
/* Temperatura a mantener se cambia con RA4 */
/*----------------------------------------------------------------------*/
#include <18F4550.h>
#fuses PLL1,CPUDIV1,USBDIV,XT,NOFCMEN,NOIESO,PUT,NOBROWNOUT,NOWDT,CCP2C1
#fuses NOPBADEN,NOLPT1OSC,MCLR,STVREN,NOLVP,NOXINST,NODEBUG,NOPROTECT
#fuses NOCPB,NOCPD,NOWRT,NOWRTC,NOWRTB,NOWRTD,NOEBTR,NOEBTRB
#device ADC=10
#use delay (clock=4M)
#include <LCD.C> // Libreria LCD.C sin modificar. LCD en PORTD

#byte TRISA=0xF92 // se define el registro TRISA como byte
#byte TRISB=0xF93
#bit RA4=0xF80.4
#bit RB0=0xF81.0

void rebote()
{
unsigned int16 j = 0;
int1 save, current;
save = 0;
for(j = 0; j < 400; j++)
9

{
if((current == RA4) != save)
j = 0;
save = current;
}
}

void main ()
{
float res, resaux=0;
float data[10];
int nro=9,j,i=0,var=20;
lcd_init();
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
TRISA=0B11111111;
TRISB=0B11111110;

while (TRUE)
{
if(RA4==0)
{
rebote();
var++;
if (var > 35)
var=20;
}
set_adc_channel (0);
delay_us(20); // Retardo para carga del condensador de muestreo
res = read_adc ();
data[i] = 5 * res * 100/1023;
i++;
if (i==nro)
{
for (j=0;j<=nro;j++)
resaux=resaux+data[j];
resaux=resaux/j;
i=0;
if(resaux<var)
RB0=1;
else
RB0=0;
}
lcd_gotoxy(1,1);
printf(lcd_putc,"Tactual:");
lcd_gotoxy(11,1);
printf(lcd_putc,"Tset:");
10


lcd_gotoxy(1,2);
printf(lcd_putc,"%4.1f'c"resaux);
lcd_gotoxy(10,2);
printf(lcd_putc,"%3d'c"var);
delay_ms(100);
}
}


PRCTICA Nro. 5: Conmutador, usando funcin rebote(). Librera LCD.C, sin cambiar. Pines de LCD cambiados
en el programa, mediante directivas y antes de la llamada a la librera.


/*----------------------------------------------------------------------*/
/* Temperatura actual por canal 0 y LM35 */
/* Temperatura a mantener se cambia con RA4 */
/*----------------------------------------------------------------------*/
#include <18F4550.h>
#fuses PLL1,CPUDIV1,USBDIV,XT,NOWDT,NOPBADEN,MCLR,NOLVP,NODEBUG,NOPROTECT
#fuses
NOFCMEN,PUT,NOBROWNOUT,CCP2C1,NOLPT1OSC,STVREN,NOXINST,NOCPB,NOCPD,NOWRT,NOWRTC,NOWRT
B,NOWRTD,NOEBTR,NOEBTRB
#device ADC=10
#use delay (clock=4M)

11

#define LCD_ENABLE_PIN PIN_E0
#define LCD_RS_PIN PIN_E1
#define LCD_RW_PIN PIN_E2
#define LCD_DATA4 PIN_C4
#define LCD_DATA5 PIN_C5
#define LCD_DATA6 PIN_C6
#define LCD_DATA7 PIN_C7
#include <LCD.C> // Libreria LCD.C sin modificar. Pines de LCD cambiados

#byte TRISA=0xF92 // se define el registro TRISA como byte
#byte TRISB=0xF93
#bit RA4=0xF80.4
#bit RB0=0xF81.0

void rebote()
{
unsigned int16 j = 0;
int1 save, current;
save = 0;
for(j = 0; j < 400; j++)
{
if((current == RA4) != save)
j = 0;
save = current;
}
}

void main ()
{
float res, resaux=0;
float data[10];
int nro=9,j,i=0,var=20;
lcd_init();
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
TRISA=0B11111111;
TRISB=0B11111110;

while (TRUE)
{
if(RA4==0)
{
rebote();
var++;
if (var > 35)
var=20;
}
12

set_adc_channel (0);
delay_us(20); // Retardo para carga del condensador de muestreo
res = read_adc ();
data[i] = 5 * res * 100/1023;
i++;
if (i==nro)
{
for (j=0;j<=nro;j++)
resaux=resaux+data[j];
resaux=resaux/j;
i=0;
if(resaux<var)
RB0=1;
else
RB0=0;
}
lcd_gotoxy(1,1);
printf(lcd_putc,"Tactual:");
lcd_gotoxy(11,1);
printf(lcd_putc,"Tset:");

lcd_gotoxy(1,2);
printf(lcd_putc,"%4.1f'c"resaux);
lcd_gotoxy(10,2);
printf(lcd_putc,"%3d'c"var);
delay_ms(100);
}
}

You might also like