.

Dependents:   Drone_Timer

Committer:
Jamestom999
Date:
Thu Jul 30 08:02:38 2015 +0000
Revision:
1:1926cb6ea141
Parent:
0:cfa2cc5fc505
7-seg library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jamestom999 0:cfa2cc5fc505 1 #include "Display.h"
Jamestom999 0:cfa2cc5fc505 2 extern int timer; //Stores timer mode
Jamestom999 0:cfa2cc5fc505 3 extern int Time; //time in 10mS
Jamestom999 0:cfa2cc5fc505 4
Jamestom999 0:cfa2cc5fc505 5 //A B C d E F g H I J K L M N O P q r S t U V W X y Z
Jamestom999 0:cfa2cc5fc505 6 int ImageTable[26]={0x77,0x1F,0x4E,0x3D,0x4F,0x47,0x7B,0x37,0x30,0x3C,0x37,0x0E,0x00,0x76,0x7E,0x67,0x73,0x46,0x5B,0x0F,0x3E,0x3E,0x00,0x37,0x3B,0x6D};
Jamestom999 0:cfa2cc5fc505 7
Jamestom999 0:cfa2cc5fc505 8 DigitalOut CS (D2);
Jamestom999 0:cfa2cc5fc505 9 SPI Display( PTD2,PTD3,PTD1);
Jamestom999 0:cfa2cc5fc505 10
Jamestom999 0:cfa2cc5fc505 11 void DisplayInit(void){
Jamestom999 0:cfa2cc5fc505 12 CS =1; //Disable chip select
Jamestom999 0:cfa2cc5fc505 13 Display.format(16,3); //16-bit, mode 3
Jamestom999 0:cfa2cc5fc505 14 Display.frequency(1000000);//1MHz clock speed
Jamestom999 0:cfa2cc5fc505 15 SendData(0x01, ShutDown ); //Normal Operation
Jamestom999 0:cfa2cc5fc505 16 SendData(0x0F, Intensity); //Brightness set to full
Jamestom999 0:cfa2cc5fc505 17 SendData(0x04, ScanLimit); //Scanning digits 1-5
Jamestom999 0:cfa2cc5fc505 18 DisplayBCD(1); //BCD decoder active on all digits
Jamestom999 0:cfa2cc5fc505 19 }
Jamestom999 0:cfa2cc5fc505 20
Jamestom999 0:cfa2cc5fc505 21 void SendData(int data, int address){
Jamestom999 0:cfa2cc5fc505 22
Jamestom999 0:cfa2cc5fc505 23 CS=0; //Enable input
Jamestom999 0:cfa2cc5fc505 24 data|=(address<<8); //Data format: XXXXAAAADDDDDDDD, X=dont care. A=address. D=data
Jamestom999 0:cfa2cc5fc505 25 Display.write(data);//Send SPI data
Jamestom999 0:cfa2cc5fc505 26 CS=1; //Disable input
Jamestom999 0:cfa2cc5fc505 27
Jamestom999 0:cfa2cc5fc505 28 }
Jamestom999 0:cfa2cc5fc505 29
Jamestom999 0:cfa2cc5fc505 30 void DisplayClear(void){//Only use when not in BCD mode.
Jamestom999 0:cfa2cc5fc505 31
Jamestom999 0:cfa2cc5fc505 32 SendData(0x00,1); //Send nothing to all the digits.
Jamestom999 0:cfa2cc5fc505 33 SendData(0x00,2);
Jamestom999 0:cfa2cc5fc505 34 SendData(0x00,3);
Jamestom999 0:cfa2cc5fc505 35 SendData(0x00,4);
Jamestom999 0:cfa2cc5fc505 36 SendData(0x00,5);
Jamestom999 0:cfa2cc5fc505 37
Jamestom999 0:cfa2cc5fc505 38 }
Jamestom999 0:cfa2cc5fc505 39
Jamestom999 0:cfa2cc5fc505 40 void DisplayBCD(int state){//1 to turn on, 0 to turn off.
Jamestom999 0:cfa2cc5fc505 41 if(state){
Jamestom999 0:cfa2cc5fc505 42 SendData(0xFF, BCD_Mode);
Jamestom999 0:cfa2cc5fc505 43 }else{
Jamestom999 0:cfa2cc5fc505 44 SendData(0x00, BCD_Mode);
Jamestom999 0:cfa2cc5fc505 45 }
Jamestom999 0:cfa2cc5fc505 46 }
Jamestom999 0:cfa2cc5fc505 47
Jamestom999 0:cfa2cc5fc505 48 void DisplayUpdate(void){
Jamestom999 0:cfa2cc5fc505 49
Jamestom999 0:cfa2cc5fc505 50 if (timer==Start){ //If timer is in start mode, increment the time
Jamestom999 0:cfa2cc5fc505 51 Time++;
Jamestom999 0:cfa2cc5fc505 52 }else if(timer==Reset){ //If timer is on reset mode, time = 0
Jamestom999 0:cfa2cc5fc505 53 Time=0;
Jamestom999 0:cfa2cc5fc505 54 }
Jamestom999 0:cfa2cc5fc505 55
Jamestom999 0:cfa2cc5fc505 56 if(timer!=Disable){ //Display the time on the 7-segment display, if enabled.
Jamestom999 0:cfa2cc5fc505 57 DisplayBCD(1);
Jamestom999 0:cfa2cc5fc505 58 SendData(DPoint| (Time/6000) , 5);
Jamestom999 0:cfa2cc5fc505 59 SendData( ((Time%6000)/1000), 4);
Jamestom999 0:cfa2cc5fc505 60 SendData(DPoint|((Time%1000)/100) , 1);
Jamestom999 0:cfa2cc5fc505 61 SendData( ((Time%100 )/10) , 2);
Jamestom999 0:cfa2cc5fc505 62 SendData( ((Time%10 ) ) , 3);
Jamestom999 0:cfa2cc5fc505 63 }
Jamestom999 0:cfa2cc5fc505 64 }
Jamestom999 0:cfa2cc5fc505 65
Jamestom999 0:cfa2cc5fc505 66 void DisplayScroll(char data[40]){//Lower case only
Jamestom999 0:cfa2cc5fc505 67 int ScreenText[50]; //Segment data for screen
Jamestom999 0:cfa2cc5fc505 68 int n,length;
Jamestom999 0:cfa2cc5fc505 69
Jamestom999 0:cfa2cc5fc505 70 for(n=0;n<50;n++){ //clear array
Jamestom999 0:cfa2cc5fc505 71 ScreenText[n]=0;
Jamestom999 0:cfa2cc5fc505 72 }
Jamestom999 0:cfa2cc5fc505 73
Jamestom999 0:cfa2cc5fc505 74 n=0;
Jamestom999 0:cfa2cc5fc505 75 while(n<40 && (data[n]!='\0')){ //keep looping untill the end of the string, max 20
Jamestom999 0:cfa2cc5fc505 76 if(data[n]>96 && data[n]<123){ //check for valid characters
Jamestom999 0:cfa2cc5fc505 77 ScreenText[n+5]=ImageTable[data[n]-97]; //use a look-up table to convert ASCII to segment data
Jamestom999 0:cfa2cc5fc505 78 }
Jamestom999 0:cfa2cc5fc505 79 n++;
Jamestom999 0:cfa2cc5fc505 80 }
Jamestom999 0:cfa2cc5fc505 81
Jamestom999 0:cfa2cc5fc505 82 timer=Disable;
Jamestom999 0:cfa2cc5fc505 83 DisplayBCD(0); //turn off decoders
Jamestom999 0:cfa2cc5fc505 84
Jamestom999 0:cfa2cc5fc505 85 length=n;
Jamestom999 0:cfa2cc5fc505 86 for(n=0;n<(length+6);n++){ //display data
Jamestom999 0:cfa2cc5fc505 87 SendData(ScreenText[n ], 5);
Jamestom999 0:cfa2cc5fc505 88 SendData(ScreenText[n+1], 4);
Jamestom999 0:cfa2cc5fc505 89 SendData(ScreenText[n+2], 1);
Jamestom999 0:cfa2cc5fc505 90 SendData(ScreenText[n+3], 2);
Jamestom999 0:cfa2cc5fc505 91 SendData(ScreenText[n+4], 3);
Jamestom999 0:cfa2cc5fc505 92 wait(0.3);
Jamestom999 1:1926cb6ea141 93 }
Jamestom999 1:1926cb6ea141 94 }
Jamestom999 1:1926cb6ea141 95
Jamestom999 1:1926cb6ea141 96 void DisplayNumber(char n1,char n2,char n3,char n4,char n5){
Jamestom999 0:cfa2cc5fc505 97
Jamestom999 1:1926cb6ea141 98 timer=Disable;
Jamestom999 1:1926cb6ea141 99 DisplayBCD(1); //turn off decoders
Jamestom999 1:1926cb6ea141 100
Jamestom999 1:1926cb6ea141 101 SendData(n1, 5);
Jamestom999 1:1926cb6ea141 102 SendData(n2, 4);
Jamestom999 1:1926cb6ea141 103 SendData(n3, 1);
Jamestom999 1:1926cb6ea141 104 SendData(n4, 2);
Jamestom999 1:1926cb6ea141 105 SendData(n5, 3);
Jamestom999 0:cfa2cc5fc505 106 }