ماژول سون سگمنت 8 رقمی دارای درایور tm1638 و 8 کلید کنترلی
شماتیک
فایل پیوست 2942
نمایش نسخه قابل چاپ
ماژول سون سگمنت 8 رقمی دارای درایور tm1638 و 8 کلید کنترلی
شماتیک
فایل پیوست 2942
نمونه سیم بندی آردوینو:
فایل پیوست 2943
کد آردوینو :
کد:# include <TM1638.h>
// Set pin numbers for connection to Arduino
# define DATA 2
# define CLOCK 3
# define STROBE 4
// Create an instance from the Library panel TM1638
TM1638 panel (DATA, CLOCK STROBE);
void setup () {
// communications through the serial port at 9600 baud
Serial . begin ( 9600 );
}
void loop () {
// create a variable to hold the status button
// in pure form (panelTlac) and to an extent 1-8 (button)
byte panelTlac panel.getButtons = ();
int Button = 0 ;
// create a variable time and storing
// the current time from activation Arduino
// seconds
long time = millis () / 1000 ;
// LED switched on with a button
// working for multiple buttons at once
panel.setLEDs (((panelTlac & 0xF0 ) << 8 ) | (panelTlac & 0xF ));
// to light the LEDs used this command and example:
// setLED (0 for off / 1 to turn on), the number of LED
/// panel.setLED (1, 4); // Turn on the fourth LED
// Translation pure forms of the extent of 1-8
switch (panelTlac) {
case 1 :
Button = 1 ;
break ;
case 2 :
Button = 2 ;
break ;
case 4 :
Button = 3 ;
break ;
case 8 :
Button = 4 ;
break ;
case 16 :
Button = 5 ;
break ;
case 32 :
Button = 6 ;
break ;
case 64 :
Button = 7 ;
break ;
case 128 :
Button = 8 ;
break ;
default :
Button = 0 ;
}
// If the button has been pressed,
// write down his number over the serial line
// and write out a sample screen character
if (Button> 0 ) {
Serial . Print ( "pressing the button" );
Serial . Println (button) ;
// extract samples of the characters in hex format
// 1 means a dot in the first digit
panel.setDisplayToHexNumber ( 0x1234ABCD , 1 );
}
// If no buttons are pressed,
// prints to display the current time from the launch
else {
// statement numbers in the format: number, dot with the second character,
// 0 for listing without zeros / 1 listing with zeros
panel.setDisplayToDecNumber (cas , 2 , 0 );
}
// Pause for a clearer statement
delay ( 500 );
}
کتابخانه ضمیمه شده است.
رفرنس:http://navody.arduino-shop.cz/navody-k-produktum/ovladaci-panel-tm1638.html
رفرنس دوم معرفی و راه اندازی مازول با آردوینو :
Arduino Code for Displaying Numbers on TM1638 Module Display | REUK.co.uk
سایر اطلاعات تکمیلی ماژول
کد اصلاح شده:
کد:
# include <TM1638.h>
// Set pin numbers for connection to Arduino
# define DATA 2
# define CLOCK 3
# define STROBE 4
// Create an instance from the Library panel TM1638
TM1638 panel (DATA, CLOCK, STROBE);
void setup () {
// communications through the serial port at 9600 baud
Serial . begin ( 9600 );
}
void loop () {
// create a variable to hold the status button
// in pure form (panelTlac) and to an extent 1-8 (button)
byte panelTlac = panel.getButtons();
int Button = 0 ;
// create a variable time and storing
// the current time from activation Arduino
// seconds
long time = millis () / 1000 ;
// LED switched on with a button
// working for multiple buttons at once
panel.setLEDs (((panelTlac & 0xF0 ) << 8 ) | (panelTlac & 0xF ));
// to light the LEDs used this command and example:
// setLED (0 for off / 1 to turn on), the number of LED
/// panel.setLED (1, 4); // Turn on the fourth LED
// Translation pure forms of the extent of 1-8
switch (panelTlac) {
case 1 :
Button = 1 ;
break ;
case 2 :
Button = 2 ;
break ;
case 4 :
Button = 3 ;
break ;
case 8 :
Button = 4 ;
break ;
case 16 :
Button = 5 ;
break ;
case 32 :
Button = 6 ;
break ;
case 64 :
Button = 7 ;
break ;
case 128 :
Button = 8 ;
break ;
default :
Button = 0 ;
}
// If the button has been pressed,
// write down his number over the serial line
// and write out a sample screen character
if (Button> 0 ) {
Serial.print("pressing the button");
Serial.println(Button) ;
// extract samples of the characters in hex format
// 1 means a dot in the first digit
panel.setDisplayToHexNumber ( 0x1234ABCD , 1 );
}
// If no buttons are pressed,
// prints to display the current time from the launch
else {
// statement numbers in the format: number, dot with the second character,
// 0 for listing without zeros / 1 listing with zeros
panel.setDisplayToDecNumber(time, 2, 0);
}
// Pause for a clearer statement
delay ( 500 );
}
آموزش راه اندازی به زبان بسکام یا بسیک
کد:
$regfile = "m32def.dat"
$crystal = 1000000
'---------------------------------
Config Porta.5 = Output ' dio
Config Porta.6 = Output ' clk
Config Porta.7 = Output ' stb
Dio Alias Porta.5 'out data
Di Alias Pina.5 'in data for scan keys
Clk Alias Porta.6 'clock
Stb Alias Porta.7 ' select
Stb = 1
'---------------------------------
Declare Sub All_zero
Declare Sub Display_brightness
Declare Sub Show_number
Declare Sub Keyscan
'---------------------------------
Dim Bef1 As Byte
Dim Num As Byte '0- 255
Dim Pos As Byte '0-15
'---------------------------------
Dim Scan0(4) As Byte
Dim Key As Byte
Dim Brightness_level As Byte
Brightness_level = &B10001111 'no Display
'---------------------------------
Dim A As Byte
Dim Ali As Byte
'---------------------------------
Wait 1
Call All_zero
Call Display_brightness
Do
Incr A
Num = A
For Ali = 0 To 15
Pos = Ali
Call Show_number
Waitms 200
Next Ali
Wait 1
Loop
End
'**********************************************************
Sub All_zero
Reset Stb
Bef1 = $40
Shiftout Dio , Clk , Bef1 , 2
Set Stb
Reset Stb
Bef1 = 0
For Ali = 0 To 15
Shiftout Dio , Clk , Bef1 , 2
Next Ali
Set Stb
End Sub
'**********************************************************
Sub Display_brightness
Reset Stb
Shiftout Dio , Clk , Brightness_level , 2
Set Stb
End Sub
'**********************************************************
Sub Show_number
Reset Stb
Bef1 = $44
Shiftout Dio , Clk , Bef1 , 2
Set Stb
Reset Stb
Pos = $c0 + Pos
Shiftout Dio , Clk , Pos , 2
Shiftout Dio , Clk , Num , 2
Set Stb
End Sub
'**********************************************************
Sub Keyscan
Reset Stb
Bef1 = $42
Shiftout Dio , Clk , Bef1 , 2
ddra.5=0
Shiftin Di , Clk , Scan0(1) , 2
Shiftin Di , Clk , Scan0(2) , 2
Shiftin Di , Clk , Scan0(3) , 2
Shiftin Di , Clk , Scan0(4) , 2
Set Stb
ddra.5=1
Key.0 = Scan0(1).0
Key.1 = Scan0(2).0
Key.2 = Scan0(3).0
Key.3 = Scan0(4).0
Key.4 = Scan0(1).4
Key.5 = Scan0(2).4
Key.6 = Scan0(3).4
Key.7 = Scan0(4).4
End Sub
خط فوق میتواند نمایشگر را روشن یا خاموش کند و زمان روشن بودن نور اون را ضعیف یا قوی کند برای این کار مقدار متغییر Brightness_level را مشخص کنیدکد:
Call Display_brightness
مطابق فایل pdf صفحه 5 آیتم 7.3 display control
به عنوان نمونه اگر شما مقدار باینری 10001000 را بدهید نمایشگر با کمترین نور روشن میشود
بیت صفر تا 3 مشخص کننده مقدار روشنایی 000 کمترین و 111 بیشترین هست
بیت 4 مشخص کننده روشن یا خاموش بودن نمایشگر است
----------------------------------------------------------------
این دستور همه ریجسترها برای نمایش را صفر میکند یا همون خاموشکد:
Call All_zero
----------------------------------------------------------------
این دستور باعث میشود مقداری در یک سون سگمت روشن شودکد:
Call Show_number
برای این کار متغییر Pos را به عنوان شماره سون سگمنت مشخص کنید و یکی از اعداد 0 یا 2 یا 4 یا 6 یا 8 یا 10 یا 12 یا 14 را دهید.
برای اینکه روی سون سگمنت مشخص شده چه مقداری نمایش داده شود متغییر Num را عددی بین 0 تا 255 دهید. که صفر باعث میشه هیچ چیزی نمایش داده نشود.
برای روشن کردن ال ای دی های بالای ماژول مقدار متغییر pos را یکی از عددهای 1 یا 3 یا 5 یا 7 یا 9 یا 11 یا 13 یا 15 دهید
برای خاموش شدن Num را صفر دهید و برای روشن شدن یک
بعد از اینکه دو متغییر num و pos را مقدار دهی کردید دستور زیر را اجرا کنید
--------------------------------------------------------------------کد:
Call Show_number
برای اسکن کردن و مشخص شدن فشرده شدن کلیدهای روی ماژول کافی است خط زیر را اجرا کنید
این دستور متغییر key را تغییر میدهد و عددی بین 0 تا 255 به شما برمیگرداند که 8 بیتی است و هر بیت مشخص کننده یک کلید است که فشرده شده یا نهکد:
Call Keyscan
عدد 0 به منزله فشرده نشدن هیچ کلید
عدد 1 به منزله فشرده شدن کلید اول
عدد 2 به منزله فشرده شدن کلید دوم
عدد 4 ... فشرده شدن کلید سوم
عدد 8 .... فشرده شدن کلید چهار
و .....
اگر مجموع 4 و 2 یعنی شش باشد یعنی کلید دوم و سوم با هم فشرده شده
-------------------------------------------
خیلی مبتدینا توضیح دادم امیدوارم همه متوجه شده باشند.
منظور از فایل pdf دیتاشیت آی سی روی برد ماژول هست به شماره MT1638
اتصال پایه های ماژول به میکروکنترلر
Porta.5 به Dio ماژول وصل شده، شما میتوانید این پایه رو تغییر دهید. ولی اگر تغییر دادید فراموش نکنید این پایه هم به عنوان خروجی و هم ورودی در زمان اسکن کلیدها استفاده شده است، پس حتما Pina.5 را هم تغییر دهید و همچنین گزینه ddra.5 را مطابق پایه انتخابی جدید خودتان تغییر دهید
نکته مهم: در ساب Keyscan اگر پایه ای از میکرو که به پایه DIO ماژول وصل شده بدرستی بصورت ورودی هنگام اسکن کلیدها تعریف نشود خطایی پیش نمیاد اما ممکنه باعث آسیب به ماژول یا میکرو شود برای این کار دو خط ddra.5=0 و ddra.5=1 را که نشان میدهد من پایه 5 از پورت A را وصل کردم به DIO ماژول، رو مطابق پایه ای که خودتان وصل کردید تغییر دهید.
پایه Porta.6 از میکرو به پایه clk ماژول وصل شود و به صورت خروجی تعریف شود.
پایه STB از ماژول به یک پایه Porta.7 از میکرو وصل شود و خروجی تعریف شود.