-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.c
161 lines (127 loc) · 3.22 KB
/
demo2.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <18F4620.h>
#fuses HS,NOLVP,NOWDT
#use delay (clock=40M)
#use fast_io(D)
#USE SPI (MASTER, SPI1, BAUD=1000000, MODE=0, BITS=16, LOAD_ACTIVE=1, STREAM=SPI_1, MSB_FIRST,IDLE=1)
#include <max7912.c>
#define Chip_Select PIN_D0
#define Chip_Select_Direction tris_d(0)
byte VR[8]; //Video RAM used to draw the screen before sending to the 8x8 matrix
int x=5 ,y=0; // starting position of ball one
int xdir=1, ydir=1; //the director ball one will go
int x1=0 ,y1=3; //starting poistion of ball two
int x1dir=1, y1dir=-1; //its starting position
//clear the "screen" - its the video ram thats getting cleared
void grx_cls(void)
{
byte x;
for (x=0;x<8; x++)
{
VR[x] = 0;
}
}
//send it to the hardware
void grx_display(void)
{
byte Addr, Row=0;
FOR (Addr = 1; Addr < 9; Addr++)
{
send7219 (Addr, VR[row++]);
}
}
//light up that LED at x,y position
void grx_setxy(byte x,y)
{
byte temp;
temp = 1;
temp <<=x;
VR[y]|=temp; // read row X at column Y
}
//turn off that LED at x,y position
void grx_unsetxy(byte x,y)
{
byte temp;
temp = 1;
temp <<=x;
temp = 255 - temp;
VR[y]&=temp; // read row X at column Y
}
//Write CHAR to the screen
VOID grx_WriteChar(byte myChar)
{
byte Column, Start_Byte;
Start_Byte = (myChar - 65) * 6; // 65 represents the letter "A" in ASCII code.
// We are using only columns from 2 through 7 FOR displaying the character.
FOR (Column = 7; Column > 1; Column--)
{
VR[Column]=Alphabet[Start_Byte++];
}
}
//scroll left the contents in the video ram
void grx_scroll(byte x,clip,dir)
{
byte scroll,edge;
edge=VR[7]; //save last row
for (scroll=7;scroll>0;scroll--)
{
VR[scroll]=VR[scroll-1];
}
VR[0]=edge; //put in the first row
}
//anitmate the bouncing balls.
void bouncing(void)
{
grx_setxy(x,y); //draw the ball one
grx_setxy(x1,y1); //draw ball two
grx_display(); //display it
Delay_ms (5) ;
grx_unsetxy(x,y); //turn them off
grx_unsetxy(x1,y1);
x= x + xdir; //new position
y =y + ydir;
if (x>=7||x<=0) //check if they hit the edges if so change direction.
{
xdir=-xdir;
}
if (y>=7||y<=0)
{
ydir=-ydir;
}
x1= x1 + x1dir; //same for ball two
y1 =y1 + y1dir;
if (x1>=7||x1<=0)
{
x1dir=-x1dir;
}
if (y1>=7||y1<=0)
{
y1dir=-y1dir;
}
}
//demo scrolling left
VOID demoone(VOID)
{
grx_scroll(1,0,0);
delay_ms(5);
grx_display(); //display it
}
VOID demotwo(VOID)
{
bouncing();
}
// Here we have the main function.
VOID main()
{
Delay_ms(100);
InitMax7219 ();
grx_cls(); // clear RAM
grx_display(); //display it
grx_WriteChar('X');
grx_display(); //display it
DO // infinite loop.
{
// You can write the characters this way, one at a time.
demoone();
//demotwo();
}WHILE (1); // do forever.
}