Mikrovezérlő

Stepper Motor Driver

/*==============================================================================
   stepper_motor.h  (tested on MINIANGLE STEPPER MOTOR 5V/1A and L298 IC)
 
   Bidirectional Stepper Motor Driver for Small Device C Compiler
   Written by Ervin Jung (2010)

HOPE RF12 FSK Transceiver Library

/*==============================================================================
   rf12.h
 
   HOPE RF12 FSK Transceiver Library 
   Written by Ervin Jung (2010)
 
   Based on: HOPE RF, RF12B programming guide
--------------------------------------------------------------------------------
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

Led villogó megszakítással

main.c

//==============================================================================
// example: Led flasher by Interrupts
// Written by Ervin Jung (2010)
//==============================================================================
 
#include "main.h"
#include <simple_delay.h>
 
char led2_state = 0;
char led1_state = 0;
 
// 5,461 ms
SIGHANDLER(timer0_handler) {
  LATDbits.LATD3 = led2_state;
  led2_state = !led2_state; 
  INTCONbits.TMR0IF = 0;
}
 
// 5,461 ms
SIGHANDLER(timer2_handler) {
  LATDbits.LATD2 = led1_state;
  led1_state = !led1_state; 

Bootloader használata

Bootloader settings

A bootloader használatához szükségesek a megfelelően előkészített startup kódok, attól függően melyiket kívánjuk használni. Ezek a kódok a crt0.c, crt0i.c és a crt0iz.c fájlokban vannak. Illetve szükséges még a megfelelően megszerkesztett Linker Script és a megfelelő compiler és linker opciók beállítása is.

Példaként nézzük a crt0i.c tartalmának egy döntő részletét, ami alapesetben a reset vektort a 0x0000 címre helyezi:

/*
 * entry function, placed at interrupt vector 0 (RESET)
 */
void _entry (void) __naked __interrupt 0
{
  __asm
    goto    __startup

HD44780 LCD egyedi karakterek

Példaprogram egyéni karakterek létrehozására és használatra.

/*==============================================================================
   Custom Charcters
   Written by Ervin Jung (2010)
 
   You can find more infromations in the lcd.h
==============================================================================*/
#include <pic18fregs.h>
 
#define  FOSC 48000000     // because PPL5 
#define  LCD_USE_DEFAULTS
#include <simple_delay.h>
#include <lcd.h>
#include <math.h>
#include <stdlib.h>

LCD_Custom_Char LCD_Custom_Char

ADC konfigurálás

Elkészült az ADC-átalakító támogatása, illetve az Usart Terminálba bekerült egy ADC monitor, amivel feldogozható két ADC érték.

Egy példaprogram a használathoz:

while (1) {
    usart_putc(1); //Begin
    printf("ADC0=%u\r\n", adc_read(ADC_CHN_0)); 
    printf("ADC1=%u\r\n", adc_read(ADC_CHN_1)); 
    usart_putc(4); //End 
    delay_ms(500);
  }

ADCConfig Usart_Terminal_ADC

AD Converter

/*==============================================================================
   analog.h optimized for IDE for PIC18F
 
   devices: pic18f2455, pic18f2550,pic18f4455, pic18f4550
 
   Written by Ervin Jung (2010)
 
--------------------------------------------------------------------------------
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 

Timers

/*==============================================================================
   timers.h optimized for IDE for PIC18F
 
   Written by Ervin Jung (2010)
 
--------------------------------------------------------------------------------
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
   This program is distributed in the hope that it will be useful,

Default config for PIC18F4550 20 Mhz (48 Mhz)

#define FOSC 48000000 
 
code char at __CONFIG1L config1l = 0xff & _PLLDIV_DIVIDE_BY_5__20MHZ_INPUT__1L & _CPUDIV__OSC1_OSC2_SRC___1__96MHZ_PLL_SRC___2__1L & _USBPLL_CLOCK_SRC_FROM_96MHZ_PLL_2_1L;
code char at __CONFIG1H config1h = 0xff & _OSC_HS__HS_PLL__USB_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H;
code char at __CONFIG2L config2l = 0xff & _PUT_ON_2L & _BODEN_ON_2L & _BODENV_2_0V_2L & _VREGEN_ON_2L;
code char at __CONFIG2H config2h = 0xff & _WDT_DISABLED_CONTROLLED_2H & _WDTPS_1_32768_2H;

Simple delay functions

/*==============================================================================
   simple_delay.h
 
   simple delay functions  
   Written by Ervin Jung (2010)
 
--------------------------------------------------------------------------------
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
   This program is distributed in the hope that it will be useful,

Tartalom átvétel