かつて初代定番PIC16F84Aのマイコンボードに7セグメントLED・SW・LED・リレー・ブザーを取付けてアッセブラによるプログラムを作成していました。今回JH7UBC 畠さんのCプログラムを使い7セグメントLEDに表示テストを行いました。
参考サイト
●PIC16F84A 7セグメントLEDの表示テスト
●PIC16F84A/84の勉強と製作
回路図
SW
LED
リレーブザー
※回路図は7セグメントLEDとSWのみ
main.c ※下記サイトのコードと異なる部分があります。
PICKit3プログラミングキット
互換器
※MPLAB X IDE 6.20までPICKit3が使用できる
MPLAB X IDE 6.20インストール
●MPLAB ®開発エコシステム ダウンロード アーカイブ
【MPLAB X v6.20】ダウンロード
画面に従ってインストールを行う
New Project
Select Device
Select Compiler
Project Name
Project Name:任意
※Encoding修正【Tools】【Options】【Enbeded 】【 Default Charset】【Shift JIS】
プログラム入力
//http://jh7ubc.web.fc2.com/pic/PIC16F84A/PIC16F84_7seg_LED.html
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (Power-up Timer is enabled)
#pragma config CP = OFF // Code Protection bit (Code protection disabled)
#define _XTAL_FREQ 10000000
void main()
{
unsigned char seg_data[10] = {
/* // 7セグメントLED用点灯パターン
//カソードコモン
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9 */
//アノードコモン
0b11000000, // 0
0b11111001, // 1
0b10100100, // 2
0b10110000, // 3
0b10011001, // 4
0b10010010, // 5
0b10000010, // 6
0b11111000, // 7
0b10000000, // 8
0b10010000 // 9
};
TRISA = 0x00; // PORTAは全て出力
TRISB = 0x00; // PORTBは全て出力
PORTA = 0x00; // PORTA初期化
PORTB = 0x00; // PORTB初期化
while(1){ // 無限ループ
for(unsigned char i=0;i<=9;i++){
PORTB = seg_data[i];
__delay_ms(1000);
}
}
}

.png)
.png)
.png)
.png)
.png)
.png)
.png)
0 件のコメント:
コメントを投稿