|
|
View previous topic :: View next topic |
Author |
Message |
trirath
Joined: 14 Jun 2010 Posts: 20 Location: Pathunthanee Thailand
|
AS1108 7 Segment Driver |
Posted: Mon Nov 22, 2010 11:00 pm |
|
|
Code: |
//////////////////////////////////////////////////////////////////////////////////////////////
// Project: Soft Spi Driver AS1108 4 digits 7 segment driver //
// Author: TRIRATH //
// Date: NOvember 2010 //
// Board: inex Board NX877 (self Modified for Support 18Fxxx) www.inex.co.th //
// Test only 3 Digits //
// Complier: CCS Complier Demo //
// Data Sheet: //
// http://www.austriamicrosystems.com/eng/Products/Lighting-Management/LED-Driver-ICs/AS1108// //
//////////////////////////////////////////////////////////////////////////////////////////////
#include <16F873A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20000000)
#use spi(MASTER,BAUD=10000,MSB_FIRST,BITS=8,MODE=0,DO =PIN_B1,CLK=PIN_B2)
//#use spi(MASTER,MSB_FIRST,BITS=8,MODE=0,DO =PIN_B1,CLK=PIN_B2) <--Another Choice
#define AS1108_Select PIN_B0
//AS1108 PIN ISET Used 47Kohms for 3 digits used,But with R 10KOhms does not work properly
//(Not test for 4 digits)
/////////////////////////////////////////////////////////////////////////////////////////////
//AS1108 Data Frame structor
//D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
//X X X X Register Address MSB------Data--------LSB
/////////////////////////////////////////////////////////////
//Register Address
#define No-Op 0x00 //not used for 1 Chip AS1108
#define Digit_1 0x01
#define Digit_2 0x02
#define Digit_3 0x03
#define Digit_4 0x04
#define Decode_Mode 0x09
#define Intensity_Control 0x0A
#define Scan_Limit 0x0B
#define Shutdown 0x0C
#define N_A 0x0D
#define Feature 0x0E
#define Display_Test 0x0F
//////////DATA // D7-D0///////////////////
//Shutdown Register (0x0C)
#define reset_mode_1 0x00 //Shutdown Mode,Reset Feature Register to Default Settings
#define reset_mode_2 0x80 //Shutdown Mode, Feature Register Unchanged
#define reset_mode_3 0x01 //Normal Operation,Reset Feature Register to Default Settings
#define reset_mode_4 0x81 //Normal Operation, Feature Register Unchanged
//////////////////////////////////////////
//////////Decode_Mode (0x09) /////////////
#define decode_mode_1 0x00 //No decode for digits 3:0
#define decode_mode_2 0x01 //Code-B/HEX decode for digit 0. No decode for digits 3:1
#define decode_mode_3 0xFF //Code-B/HEX decode for digits 3:0
/////////////////////////////////////////
//////////Display_Test (0x0F) ///////////
#define display_test_mode_1 0x00 //Normal Operation
#define display_test_mode_2 0x01 //Display Test Mode
/////////////////////////////////////////
//Intensity Control Register (0x0A) have 16 Level brightness
#define intensity_level_0 0x00 // 1/32 (min on) 0xX0
#define intensity_level_1 0x01 // 3/32 0xX1
#define intensity_level_2 0x02 // 5/32 0xX2
#define intensity_level_3 0x03 // 7/32 0xX3
#define intensity_level_4 0x04 // 9/32 0xX4
#define intensity_level_5 0x05 // 11/32 0xX5
#define intensity_level_6 0x06 // 13/32 0xX6
#define intensity_level_7 0x07 // 15/32 0xX7
#define intensity_level_8 0x08 // 17/32 0xX8
#define intensity_level_9 0x09 // 19/32 0xX9
#define intensity_level_10 0x0A // 21/32 0xXA
#define intensity_level_11 0x0B // 23/32 0xXB
#define intensity_level_12 0x0C // 25/32 0xXC
#define intensity_level_13 0x0D // 27/32 0xXD
#define intensity_level_14 0x0E // 29/32 0xXE
#define intensity_level_15 0x0F // 31/32 (max on) 0xXF
////////////////////////////////////////////////////////////
/////////Scan-Limit Register (0x0B)
#define Scan_Limit_mode_1 0x00 //Display digit 0 only
#define Scan_Limit_mode_2 0x01 //Display digits 0:1
#define Scan_Limit_mode_3 0x02 //Display digits 0:2
#define Scan_Limit_mode_4 0x03 //Display digits 0:3
///////////////////////////////////////////////////////////
////////////Feature 0x0E
#define my_feature 0b00001001
#define ZERO 0b00000000
#define ONE 0b00000001
#define TWO 0b00000010
#define THREE 0b00000011
#define FOUR 0b00000100
#define FIVE 0b00000101
#define SIX 0b00000110
#define SEVEN 0b00000111
#define EIGHT 0b00001000
#define NINE 0b00001001
#define BLANK 0b00001111
//set Bit D7 if need to display Dot
void sent_to_AS1108(unsigned char cmd_register ,unsigned char data ){
output_low(AS1108_Select);
delay_cycles(4);
spi_xfer(cmd_register);
spi_xfer(data);
output_high(AS1108_Select);
}
unsigned char mask(unsigned char num) {
switch (num) {
case 0 : return ZERO;
case 1 : return ONE;
case 2 : return TWO;
case 3 : return THREE;
case 4 : return FOUR;
case 5 : return FIVE;
case 6 : return SIX;
case 7 : return SEVEN;
case 8 : return EIGHT;
case 9 : return NINE;
}
}
void main(void){
unsigned char digit;
unsigned int16 i;
sent_to_AS1108(Feature,my_feature); //USe Code-B and enable SPI,NO Blinking
sent_to_AS1108(Shutdown,reset_mode_3); //Normal Operation, Feature Register Unchanged
sent_to_AS1108(Display_Test,display_test_mode_1); //Normal Operation
sent_to_AS1108(Decode_Mode,decode_mode_3); //Code-B/HEX decode for digits 3:0
sent_to_AS1108(Intensity_Control,intensity_level_15); // 31/32 (max on)
sent_to_AS1108(Scan_Limit,Scan_Limit_mode_3); //display only 3 digits form 4
while(TRUE){
for(i=0;i<1000;i++){ //test count up 0-999
digit = i % 10 ;
sent_to_AS1108(Digit_1,mask(digit));
digit = (i/10)%10 ;
sent_to_AS1108(Digit_2,mask(digit));
digit = (i/100)%100 ;
if(mask(digit)==0) sent_to_AS1108(Digit_3,BLANK); //NO DISPLAY ZERO on digit No3
else sent_to_AS1108(Digit_3,mask(digit));
Delay_ms(100);
}
}//end while
}//end main
|
|
|
|
tong143
Joined: 09 May 2011 Posts: 14
|
|
Posted: Tue May 10, 2011 12:59 am |
|
|
can we use this for pic 16F72 |
|
|
vladtess
Joined: 14 May 2011 Posts: 26
|
|
Posted: Thu May 19, 2011 9:18 am |
|
|
Thanks, looks intense! It would be great to post a sample schematic with it. |
|
|
trirath
Joined: 14 Jun 2010 Posts: 20 Location: Pathunthanee Thailand
|
|
Posted: Thu Jun 16, 2011 9:48 pm |
|
|
You can connect with vary PIC16F or 18F if there are I/O pin (TTL).
In a part of schematic you can see in data sheet AS1108 that show how to connect AS1108 with seven segment (Common Cathode and total 12 wires ). Also ISET pin (PIN 15 ) with R47K if the circuit use power supply 5 volts (AS1108 data sheet page 1 and page 14).
Also there are only 3 wires connect during pic and As1108. Please see details on demo program. In this case we use PortB 16F873A as following:
RB0 = AS1108_Select (PIN 9)
RB1 = Din AS1108 (PIN 2), not use PIN1 of AS1108
RB2 = clk pin of as1108 (PIN 10) |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|