تبلیغات
مشاوره ، طراحی و ساخت تجهیزات الكترونیكی - راه اندازی ماژول سون سگمنت 4 رقمی با آردوینو
مشاوره ، طراحی و ساخت تجهیزات الكترونیكی

مرتبه
تاریخ : یکشنبه 10 آبان 1394

ماژول سون سگمنت 4 رقمی - دارای ممیز - دو نقطه ساعت و علامت درجه

مناسب ساخت ساعت ، دماسنج ، شمارنده و...

قابلیت راه اندازی 4 عدد سون سگمنت تنها با 3 پایه از میکروکنترلر

با قابلیت سری کردن چندین ماژول برای صرفه جویی در پین های IO

برای خرید ماژول کلیک کنید

نمونه کد راه اندازی ماژول با آردوینو و بسکام

نمونه کد راه اندازی ماژول سون سگمنت با arduino :

//M365 74HC595 8-DIGIT SEVEN SEGMENT DRIVER
//M.OMIDVAR SHIRAZ-IRAN-2016
//WEBLOG:  http://mtronics.ir
//SHOP:    http://iecshop.ir
//PHONE:   +98 935 318 1040

int dataPin = 2;//DIO
int latchPin = 3;//SCLK
int clockPin = 4;//RCLK
const byte ARRAY_SIZE = 35;
byte segment_codes[ARRAY_SIZE];
String available_chars[ARRAY_SIZE];
String s1;String s2;String s3;String s4;
String s5;String s6;String s7;String s8;
boolean degree;boolean clockdot;

void setup() {
  available_chars[0] = "0";
  available_chars[1] = "1";
  available_chars[2] = "2";
  available_chars[3] = "3";
  available_chars[4] = "4";
  available_chars[5] = "5";
  available_chars[6] = "6";
  available_chars[7] = "7";
  available_chars[8] = "8";
  available_chars[9] = "9";
  available_chars[10] = "A";
  available_chars[11] = "b";
  available_chars[12] = "D";
  available_chars[13] = "c";
  available_chars[14] = "d";
  available_chars[15] = "E";
  available_chars[16] = "F";
  available_chars[17] = "H";
  available_chars[18] = "h";
  available_chars[19] = "L";
  available_chars[20] = "n";
  available_chars[21] = "I";
  available_chars[22] = "O";
  available_chars[23] = "o";
  available_chars[24] = "P";
  available_chars[25] = "S";
  available_chars[26] = " ";
  available_chars[27] = "-";
  available_chars[28] = "u";
  available_chars[29] = "J";
  available_chars[30] = "_";
  available_chars[31] = "g";
  available_chars[32] = "r";
  available_chars[33] = "t";
  available_chars[34] = "y";

  segment_codes[0]=0b11000000;
  segment_codes[1]=0b11111001;
  segment_codes[2]=0b10100100;
  segment_codes[3]=0b10110000;
  segment_codes[4]=0b10011001;
  segment_codes[5]=0b10010010;
  segment_codes[6]=0b10000011;
  segment_codes[7]=0b11111000;
  segment_codes[8]=0b10000000;
  segment_codes[9]=0b10011000;
  segment_codes[10]=0b10001000;
  segment_codes[11]=0b10000011;
  segment_codes[12]=0b11000110;
  segment_codes[13]=0b10100111;
  segment_codes[14]=0b10100001;
  segment_codes[15]=0b10000110;
  segment_codes[16]=0b10001110;
  segment_codes[17]=0b10001001;
  segment_codes[18]=0b10001011;
  segment_codes[19]=0b11000111;
  segment_codes[20]=0b10101011;
  segment_codes[21]=0b11111001;
  segment_codes[22]=0b11000000;
  segment_codes[23]=0b10100011;
  segment_codes[24]=0b10001100;
  segment_codes[25]=0b10010010;
  segment_codes[26]=0b11111111;
  segment_codes[27]=0b10111111;
  segment_codes[28]=0b11000001;
  segment_codes[29]=0b11110001;
  segment_codes[30]=0b11110111;
  segment_codes[31]=0b10010000;
  segment_codes[32]=0b10101111;
  segment_codes[33]=0b10000111;
  segment_codes[34]=0b10010001;
 
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
 
s1="1";s2="2";s3="3";s4="4";
degree=0;//0=OFF - 1=ON
clockdot=1;//0=OFF - 1=ON


//special config for M365 - FOUR DIGITS SEGMENT DRIVER
if (clockdot==1) s5="8."; else s5=" "; // :on>>s5="8." :off>>s5=" "
if (degree==1)s6="8."; else s6=" ";// degree-on>>s6="8." degree-off>>s6=" "
show("  "+String(s6)+String(s5)+String(s4)+String(s3)+String(s2)+String(s1));
//special config for M365 - FOUR DIGITS SEGMENT DRIVER
}


void show(String value){
  int skip = 0;
  for(int i=0; i<value.length(); i++) {
   // for(int i=value.length(); i>1; i--) {
    if(!((String)value[i]).equals(".")) {
      int indexOfCharToWrite = findIndexOfChar((String)value[i]);
      if(indexOfCharToWrite > -1){
        byte bitToWrite = 0;
        digitalWrite(latchPin, LOW);
        byte code = segment_codes[indexOfCharToWrite];
        boolean skipNext = false;
        if(((String)value[i+1]).equals(".")) {
          bitWrite(code, 7, 0);
          skipNext = true;
        }
        shiftOut(dataPin, clockPin, MSBFIRST, code);
        bitWrite(bitToWrite, i-skip, 1);
        shiftOut(dataPin, clockPin, LSBFIRST, bitToWrite);
        digitalWrite(latchPin, HIGH);
        if(skipNext){
          skip++;
        }
      }
    }
  }
}

int findIndexOfChar(String character){
  int wantedpos = -1;
  for(int i=0; i< ARRAY_SIZE; i++){
    if(character.equals(available_chars[i])){
      wantedpos = i;
      break;
    }
  }
  return wantedpos;
}

نمونه کد راه اندازی ماژول سون سگمنت با بسکام bascom avr :

'demo code for m365 segment driver http://iecshop.ir
''****************************CONFIG MCU***********************************
$regfile = "m328def.dat"
$hwstack = 700
$swstack = 700
$framesize = 600
$crystal = 16000000
'****************************CONFIG 7 SEGMENT***********************************
Cds Alias Portd.2                                           ' data
Cclk Alias Portd.3                                          ' clk
Css Alias Portd.4                                           ' le
Config Cds = Output
Config Cclk = Output
Config Css = Output
'***************
Config Single = Scientific , Digits = 2                     '*
Dim Dotbit As Bit , Dot As Byte , Minus As Byte , Clock As Byte , Clockplace As Byte
Dim Sr As String * 6 , Esr As String * 2                    '*
Dim Cnt As Word , _ch As Word                               '*
Dim Number_digit As Single                                  '*
Dim Temp1 As Single
'*******************************************************************************
Dim 7bit As Bit , Anod As Word , Num As Byte At Anod + 1 Overlay , Seg As Byte At Anod + 0 Overlay
'*******************************************************************************
Dim Head As String * 10
Dim I As Word
Dim J As Word                                               '*
'*********************************main******************************************
Do

For I = 0 To 3
For J = 0 To 2000
Sr = "03:14" : Gosub Show_temp_humid
Next J
For J = 0 To 2000
Sr = "0314" : Gosub Show_temp_humid
Next J
Next I

For J = 0 To 8000
  Temp1 = -5.2
  Head = Str(temp1)
   Head = Format(head , "00.0")
   Sr = Mid(head , 1 , 4) + "'c" : Gosub Show_temp_humid
Next J



For I = 0 To 10000
   Sr = "1.618" : Gosub Show_temp_humid
Next I



Loop
End
'**********************************code numbers**************************************
Numbers:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144 , 127 , 191 , 158
'                                            ".""-"  "c"
Dotplace:
Data 0 , 0 , 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256
Segplace:
Data 0 , 1 , 2 , 4 , 8 , 16 , 32 , 64
Segnumber:
Data 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128
'************************************************************************************
'***********************************data to 7 segment***************************
Timer_7seg:
Css = 0 : Shiftout Cds , Cclk , Anod , 1 , 16 : Css = 1
Return
'*********************************mohsabe adad be 7segment**********************
Show_temp_humid:
Dot = Charpos(sr , ".")
Seg = Lookup(dot , Dotplace) : Num = 127
Gosub Timer_7seg
Minus = Charpos(sr , "-")
Seg = Lookup(minus , Segplace) : Num = 191
Gosub Timer_7seg
Clock = Charpos(sr , ":")
Head = Mid(sr , 3 , 1)
If Head = ":" Then
Seg = 16 : Num = 127
Gosub Timer_7seg
Delchar Sr , Clock
End If
Delchar Sr , Dot
For _ch = 1 To 6
Esr = Mid(sr , _ch , 1)
If Esr = "-" Then Goto Nex1 : Num = Val(esr)
If Esr = "'" Then : Seg = 32 : Num = 127
Delchar Sr , _ch
Gosub Timer_7seg
Decr _ch
Goto Nex1
End If
Cnt = _ch
Seg = Cnt -1 : : Seg = 2 ^ Seg
Num = Lookup(num , Numbers)
If Esr = "c" Then Num = Lookup(12 , Numbers)
Gosub Timer_7seg
Nex1:
Next
Anod = &HFF00
Num = Lookup(127 , Numbers)
Gosub Timer_7seg
Return




طبقه بندی: اطلاعات كاربردی، 
برچسب ها: راه اندازی سون سگمنت با آردوینو،
ارسال توسط محمد امیدوار
پیوند های روزانه
امکانات جانبی
mtronics
محصولات
tester MX602B
tester MX604C

ابزار وبلاگ

cb:loop_post_related_link