Bagaimana anda ingin menyalakan 7 Segment atau membuat kiraan nombor?
Langkah pertama anda perlu tahu cara sambungannya. Untuk di sambungkan kepada Microcontroller PIC, anda boleh memilih sama ada menggunakan 7 segment Common anode atau Common Cathode. Sambungannya seperti di bawah.
Anda perlu memberi signal yang betul untuk menunjukkan nombor di 7 segment. Berikut adalah jadual penukaran daripada nombor decimal kepada kod 7 segment.
DECIMAL | 7 SEGMENT | |||||||||
A3 | A2 | A1 | A0 | a | b | c | d | e | f | g |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
Di bawah adalah videonya
PIC Source Code
/*
Project: Seven Segment Lesson
Programmer: Shahrulnizam Mat Rejab
Microcontroller (Crystal Frequency):
PIC16F877A (20MHz), PIC16F887 (20MHz), PIC16F1939 (Internal 32MHz)
PIC18F4520 (10MHz), PIC18F4550 (10MHz), PIC18F46K22 (Internal 16MHz)
Arduino
Compiler: HI-TECH C for PIC10/12/16 V9.83, PIC18 V9.80
Last Modified: 29 November 2014
Website: http://shahrulnizam.com
*/
#if defined (_16F877A) || (_16F887)
#define SEGMENT PORTD
#elif defined (_16F1939) || (_18F4520) || (_18F4550) ||(_18F46K22)
#define SEGMENT LATD
#elif defined (_18F26K22)
#define SEGMENT LATB
#endif
#include "LibraryHardware.h"
static const char segment[]={ //.abcdefg
0b01111110,0b00110000,0b01101101,0b01111001,0b00110011,
0b01011011,0b01011111,0b01110000,0b01111111,0b01111011,
};
void setup()
{
initialize();
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
#if !defined (_18F26K22)
TRISD=0b00000000;
TRISE=0b00000000;
#endif
BUZZER=1;
}
void loop()
{
int i;
for(i=0;i<=9;i++){
SEGMENT=segment[i];
delay(1000);}
}
7 responses to “PIC Lesson: Seven Segment”
uiks. ini ilmu baru nih..
mcm mana nak tahu beza
__CONFIG(0x3F3A);
AND
_CONFIG ( 0x3F32 );
saya try wat 7 segment guna yg kedua tak dapat
saya nak tanya, saya dah try burn program ni dalam pic, tapi….tak dapat
I created the hex file with MPLAB 8.86, but once simulated RealPic Simulator 1.3, are not displayed correctly number from 0 to 9.
Where did I go wrong?
Thank you.
This is my hex (seven_segments.hex):
:100000000A128A11832F00308A000408840A8207AA
:1000100000347E3430346D34793433345B345F34BF
:0600200070347F347B34D4
:100F060083010A128A11BD2F8316031788018901EE
:100F1600080083160313850186018701880189016C
:100F26000A128A1187270A128A118312031385016E
:100F360086018701880189010800F401F501B12FB6
:100F46000730F3007D30F200F20BA72FF30BA72F2B
:100F56000130F4070318F50A0030F5077108750229
:100F6600031DB72F70087402031CBA2FBB2FA32FC3
:100F7600BC2F08000A128A118C270A128A11C32F65
:100F8600F601F7017708803AFF0080307F02031DE3
:100F9600CE2F0A307602031CD12FD22FD42FC32F87
:100FA600C32F7608013E84000A128A1103200A1212
:100FB6008A11831203138800E830F0000330F10031
:100FC6000A128A11A0270A128A110130F60703189D
:100FD600F70A0030F7077708803AFF0080307F0273
:100FE600031DF72F0A307602031CFA2FFB2FD42F8E
:0A0FF600C32FC32F0A128A1100282E
:02400E00E2ECE2
:00000001FF
File seven_segments.rpp of RealPic Simulator 1.3:
[Real Pic Simulator]
Version=1.3.0.0
HexFile=seven_segments.hex
Processor=16F887
RealFrequency=20000000
SimFrequency=20000000
[Visual]
Component0=07,003E,002B,000000008300008083010081830200828303008383040084830500858306008685002000
Vito, you paste hex file, how can I understand that. Just follow software, compiler and PIC I use.
PS: of course I used the Hi-Tech C compiler in MPLAB. 🙂
here not show any PIC Source Code