Till KTH:s startsida Till KTH:s startsida

LPC Low pin Count Demo-board (sw)

Experiment med PICkit2 och "Low pin Count Demo" -board

Krets PIC16F690

pdf LPC-schema   Kontakt J1    

pdf Low Pin Count User's Guide   pdf PICkit 2 Microcontroller Programmer User's Guide

demoboard.gif

LPC printead circuit board   Kontakt J1     LPC ASCII-grafik:  text.gif lpc.txt

Vårt testprogram: Play a melody ...

Kodexempel för PIC16F690:

c.gif mel690.c  c.gif lookup.c   c.gif lookup2.c  


Hello world! - Tänd en LED

Kodexempel för PIC16F690:

 
/* helloled.c  PICkit 2 Lesson 1 Light up a LED */ 
 
/*    Low pin count demo board               J1
         ___________  ___________           1 RA5
        |           \/           |          2 RA4
  +5V---|Vdd     16F690       Vss|---GND    3 RA3
     ---|RA5        RA0/AN0/(PGD)|-<-RP1    4 RC5
     ---|RA4            RA1/(PGC)|---       5 RC4
  SW1---|RA3/!MCLR/(Vpp)  RA2/INT|---       6 RC3
     ---|RC5/CCP              RC0|->-DS1    7 RA0
     ---|RC4                  RC1|->-DS2    8 RA1
  DS4-<-|RC3                  RC2|->-DS3    9 RA2
        |RC6                  RB4|         10 RC0
        |RC7               RB5/Rx|         11 RC1
        |RB7/Tx               RB6|         12 RC2
        |________________________|         13 +5V
                                           14 GND
*/
 
/* B Knudsen Cc5x C-compiler - not ANSI-C */
#include "16F690.h"
#pragma config |= 0x00D4 
 
void main( void)
{
  TRISC.0 = 0;
  PORTC.0 = 1;
 
  while(1)
    {
      nop();
    }
}

c.gif helloled.c


Blinka med lysdioden!

 
/* blinkled.c  PICkit2 Lesson 2 Blink a LED */ 
 
/*    Low pin count demo board               J1
         ___________  ___________           1 RA5
        |           \/           |          2 RA4
  +5V---|Vdd     16F690       Vss|---GND    3 RA3
     ---|RA5        RA0/AN0/(PGD)|-<-RP1    4 RC5
     ---|RA4            RA1/(PGC)|---       5 RC4
  SW1---|RA3/!MCLR/(Vpp)  RA2/INT|---       6 RC3
     ---|RC5/CCP              RC0|->-DS1    7 RA0
     ---|RC4                  RC1|->-DS2    8 RA1
  DS4-<-|RC3                  RC2|->-DS3    9 RA2
        |RC6                  RB4|         10 RC0
        |RC7               RB5/Rx|         11 RC1
        |RB7/Tx               RB6|         12 RC2
        |________________________|         13 +5V
                                           14 GND
*/
 
/* B Knudsen Cc5x C-compiler - not ANSI-C */
#include "16F690.h"
#pragma config |= 0x00D4 
 
void delay10( char n);
 
void main( void)
{
  TRISC.0 = 0;
 
  while(1)
    {
        PORTC.0 = 1;
        delay10(200);
        PORTC.0 = 0;
        delay10(200);
    }
}
 
void delay10( char n)
/*
  Delays a multiple of 10 milliseconds using the TMR0 timer
  Clock : 4 MHz   => period T = 0.25 microseconds
  1 IS = 1 Instruction Cycle = 1 microsecond
  error: 0.16 percent
*/
{
    char i;
 
    OPTION = 7;
    do  {
        i = TMR0 + 39; /* 256 microsec * 39 = 10 ms */
        while ( i != TMR0)
            ;
    } while ( --n > 0);
}
 
 

c.gif blinkled.c


Rinnande ljus!

/* rotateled.c  PICkit2 Lesson 3 Rotate LED light */
 
/*    Low pin count demo board               J1
         ___________  ___________           1 RA5
        |           \/           |          2 RA4
  +5V---|Vdd     16F690       Vss|---GND    3 RA3
     ---|RA5        RA0/AN0/(PGD)|-<-RP1    4 RC5
     ---|RA4            RA1/(PGC)|---       5 RC4
  SW1---|RA3/!MCLR/(Vpp)  RA2/INT|---       6 RC3
     ---|RC5/CCP              RC0|->-DS1    7 RA0
     ---|RC4                  RC1|->-DS2    8 RA1
  DS4-<-|RC3                  RC2|->-DS3    9 RA2
        |RC6                  RB4|         10 RC0
        |RC7               RB5/Rx|         11 RC1
        |RB7/Tx               RB6|         12 RC2
        |________________________|         13 +5V
                                           14 GND
*/
 
/* B Knudsen Cc5x C-compiler - not ANSI-C */
#include "16F690.h"
#pragma config |= 0x00D4 
 
void delay10( char n);
 
void main( void)
{
  TRISC = 0;
  char led_state = 1;
 
  while(1)
    {
        Carry = led_state.3;
        led_state = rl(led_state);
        PORTC = led_state;
        delay10(200);
    }
}

void delay10( char n)
{
    char i; OPTION = 7;
    do  {
        i = TMR0 + 39; /* 256 microsec * 39 = 10 ms */
        while ( i != TMR0) ;
        } while ( --n > 0);
}

c.gif rotateled.c  


Analoga spänningar - AD-omvandlaren

 
/* adblink.c  PICkit2 Read pot RP1 with AD AN0 and blink LED DS1 */ 
 
/*    Low pin count demo board               J1
         ___________  ___________           1 RA5
        |           \/           |          2 RA4
  +5V---|Vdd     16F690       Vss|---GND    3 RA3
     ---|RA5        RA0/AN0/(PGD)|-<-RP1    4 RC5
     ---|RA4            RA1/(PGC)|---       5 RC4
  SW1---|RA3/!MCLR/(Vpp)  RA2/INT|---       6 RC3
     ---|RC5/CCP              RC0|->-DS1    7 RA0
     ---|RC4                  RC1|->-DS2    8 RA1
  DS4-<-|RC3                  RC2|->-DS3    9 RA2
        |RC6                  RB4|         10 RC0
        |RC7               RB5/Rx|         11 RC1
        |RB7/Tx               RB6|         12 RC2
        |________________________|         13 +5V
                                           14 GND
*/
 
/* B Knudsen Cc5x C-compiler - not ANSI-C */
#include "16F690.h"
#pragma config |= 0x00D4 
 
void delay( char );
 
void main( void)
{
  TRISA.0 = 1;
  TRISC.0 = 0;
  char time;
  bit DS1_led;
  
  /* AD setup */ 
  ANSEL.0 = 1;
  ADCON1 = 0b0.001.0000; /* AD conversion clock 'fosc/8' */
  /* 
     0.x.xxxx.x.x  ADRESH:ADRESL is 10 bit left justified
     x.0.xxxx.x.x  Vref is Vdd
     x.x.0000.x.x  Channel 00 (AN0)
     x.x.xxxx.0.x  Go/!Done start later
     x.x.xxxx.x.1  Enable AD-converter
  */
  ADCON0 = 0b0.0.0000.0.1; 
 
  while(1)
    {
        GO=1;          /* start AD                               */
        while(GO);     /* wait for done                          */ 
        time = ADRESH; /* only using 8 MSB of ADRES (=ADRESH)    */
        /* must negate 'time' to increase blink speed            */ 
        /* when turning RP1 clockwise                            */
        time = ~time;
        DS1_led = !DS1_led; /* toggle DS1 LED-light on/off       */
        PORTC.0 = DS1_led;  
        delay(10);          /* add a minimum 10 ms delay         */
        delay(time);
    }
}


void delay( char millisec)
{
OPTION = 2; /* prescaler divide by 8 */
do {
TMR0 = 0;
while ( TMR0 < 125) ;
} while ( -- millisec > 0);
}

c.gif adblink.c 


Prova interrupt!

Kodexempel för 16F690:

 
/* kilroy.c  PICkit2 Test interrupt SW1 and DS1 */
 
/*   "Low pin count demo board"              J1
         ___________  ___________           1 RA5
        |           \/           |          2 RA4
  +5V---|Vdd     16F690       Vss|---GND    3 RA3 --
     ---|RA5        RA0/AN0/(PGD)|-<-RP1    4 RC5   |
     ---|RA4            RA1/(PGC)|---       5 RC4   | insert
  SW1---|RA3/!MCLR/(Vpp)  RA2/INT|---       6 RC3   Resistor 1k 
     ---|RC5/CCP              RC0|->-DS1    7 RA0   |
     ---|RC4                  RC1|->-DS2    8 RA1   |
  DS4-<-|RC3                  RC2|->-DS3    9 RA2 --
        |RC6                  RB4|         10 RC0
        |RC7               RB5/Rx|         11 RC1
        |RB7/Tx               RB6|         12 RC2
        |________________________|         13 +5V
                                           14 GND
*/
 
/* Insert resistor 1k (value not critical) between J1:3 and J1:9 */  
/* for SW1 to be able to generate external interrupt             */
 
/* B Knudsen Cc5x C-compiler - not ANSI-C */
#include "16F690.h"
#include "int16Cxx.h"
#pragma config |= 0x00D4 
 
#pragma origin 4
interrupt int_server( void ) /* the place for the interrupt routine */
{
  int_save_registers
  if( INTF == 1 )  /* test if it is the INT-interrupt?         */
    {              /* this time it's obvius that it is!        */
      PORTC.0 = 1; /* Lightdiode on to show "Killroy was here" */
      INTF = 0;    /* Reset INT-flag before leaving            */
    }
  int_restore_registers
}
 
/* include no code before the interrupt routine */
void delay( char);
 
void main( void)
{
  TRISC.0 = 0; /* RC0 is output  */
  PORTC.0 = 0; /* the LED is off */
  delay(10);   /* 10 ms for demo board initialization              */
               /* or uncheck !MCLR after Vdd is checked in PICkit2 */ 
  TRISA.2 = 1; /* INT is input   */
  ANSEL = 0;   /* PORTA dig i/o  */
 
  INTEDG  = 0;   /* interrupt on negative going edge                */
                 /* eg when you press SW1 (it's connected that way) */
  INTE    = 1;   /* local enable  */
  GIE     = 1;   /* global enable */
 
  while(1)
    {
      nop(); /* the LED is still off */
    }
}

void delay( char millisec)
{
OPTION = 2; /* prescaler divide by 8 */
do {
TMR0 = 0;
while ( TMR0 < 125) ;
} while ( -- millisec > 0);
}

c.gif kilroy.c   NOTE! copy the header file  int16Cxx.h  from the compiler folder to your Work folder.