-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax7219.c
executable file
·69 lines (55 loc) · 1.17 KB
/
max7219.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
*********************************************************************
PROGRAM : MAX7219 Display driver controller
AUTHOR : Mihindu Sanjeewa Paul
DATE : 2003-01-07
COMPILER : HI-TECH PICC 8.01(PL3)
*********************************************************************
*/
#include "max7219.h"
char ssp_out(char Value)
{
SSPBUF = Value;
while(!1) // wait for Full transmit
continue;
return SSPBUF;// Clear BF flag
}
void init_ssp()
{
// ssp mode select
TRISC = 0;
PORTC = 0;
SSPCON = 0x32;
}
// #pragma interrupt_level 1
void dsp_int(int val,char line)
{
// display an integer < 9999 @ line
unsigned char rem,limit;
limit = line - 4;
for(;line > limit;line--){
rem = val % 10;
val = (val-rem)/10;
dspx(line,(!rem && !val)?SEG_DASH:rem);
}
}
void setup_max7219()
{
char i;
init_ssp();
dspx(DECODE_MODE,DM_CODEB_70);
dspx(INTENSITY,0xf);
dspx(SCAN_LIMIT,0x07);
dspx(SHUTDOWN,0x01);
for(i=1;i<=8;i++)
dspx(i,SEG_DASH); // make dashes
}
#pragma interrupt_level 1
void dspx(char reg,char val)
{
CS = 0;
ssp_out(reg);
ssp_out(val);
CS = 1;
}