Писать код буду на языке С в программе MPLAB X IDE 5.35 на российской бесплатной ОС Linux Rosa Fresh R13 Plasma – как всё быстро и бесплатно установить читайте здесь: “микроник.рус/7259/”.
Как создать проект в MPLAB X IDE читайте в PDF инструкции:
– скачать pdf инструкцию по написанию кода и созданию проекта (краткая – пару страниц).
Прошивку микросхемы делал в IC-Prog – скачать её для Windows XP можно здесь в конце записи: “микроник.рус/5666/”
Давайте сначала просто зажжём светодиоды:
Схема:
Код на Си:
#include <xc.h>
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
// Configuration Byte
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
void main() //The main function
{
TRISC = 0b00000000; //PORTC как выходы.
PORTC = 0b10101010; //Зажигаем RC1,3,5,7
}
Скачать hex и С файлы:
– скачать в zip архиве
– скачать в tar.gz архиве
Прошивка в IC-Prog (на рисунке ниже еще отмечена галочка на WDT – но можно и без неё, как в коде выше, главное чтобы HS параметр был поставлен – то есть работа от кварца):
——————————————
Мигаем светодиодами на языке Си на pic16f877a
————————————————-
Код:
#include <xc.h>
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
// Configuration Byte
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
void main() //The main function
{
TRISC = 0b00000000; //Instruct the MCU that the PORTB pins are used as Output.
PORTC = 0b00001111; //Make all output of RB3 LOW
while(1)
{
PORTC = 0b10101010; //Pin1 of PORTC high
__delay_ms(1000); //Delay of 1 sec
PORTC = 0b01010101; //Pin1 of PORTC low
__delay_ms(1000); //Delay of 1 sec
}
}
Вышеуказанный код мигает светодиодами на ножках PORTC
Схема подключения аналогичная:
Скачать hex и С файлы:
– скачать в zip архиве
– скачать в tar.gz архиве



