{
*****************************************************************************
* Name : testing routine.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 2/4/2014 *
* Version : 1.0 *
* Notes : letter testing routine *
* : *
*****************************************************************************
}
Device = 18F2420
Clock = 8
// import LCD library...
Include "convert.bas"
Include "InternalOscillator.bas"
Include "Utils.bas" // Include this file when we compile so that we can use keywords like 'setalldigital'
Include "shift.bas"
// Arrays
Const R_L_Data(8) As Byte = (%00000000, 'anodes right to left
%00000000,
%00000001,
%00000001,
%00000001,
%00000001,
%00000001,
%00000001)
Const T_B_Data(8) As Byte =(%11111110, 'top
%11111101,
%11111011,
%11110111, ' cathodes colums
%11101111, ' top to bottom
%11011111,
%10111111,
%01111111) 'bottom
// variable declaration
Dim x As Byte
Dim y As Byte
Dim index As Byte
// Sub Routines
// Start Of Program
y = 0
SetAllDigital // Make all Pins digital I/O's
TRISC = %00000000 // Make PORTD all outputs
TRISB = %00000000 // Make PORTB all outputs
index = 0
// Main Loop
While True() // This creates an infinite loop
for x = 0 to 7
' x = 0
'y = 0
' PORTC = Y_Data(x) >>8
'PORTB = X_data(x)
' DelayMS(10)
PORTC =T_B_Data(x) ' anodes
PORTB = 0 'cathodes
delayms(1000)
PORTB = 1
' delayms(500)
Next
Wend // Loop back to the while loop as long as we havent finished.
{
*****************************************************************************
* Name : testing routine.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 2/4/2014 *
* Version : 1.0 *
* Notes : letter testing routine *
* : *
*****************************************************************************
}
DEVICE = 18F2420
CLOCK = 8
// import LCD library...
INCLUDE "convert.bas"
INCLUDE "InternalOscillator.bas"
INCLUDE "Utils.bas" // Include this file when we compile so that we can use keywords like 'setalldigital'
INCLUDE "shift.bas"
// Arrays
// Arrays
CONST B_data(8)AS BYTE = (%11111110, // K
%11111101,
%11111011,
%11110111,
%11101111,
%11011111,
%10111111,
%01111111)
CONST K0(8)AS BYTE = (%00000001, // K
%00000001,
%00000001,
%00000001,
%00000001,
%00000001,
%00000001,
%00000001)
CONST K1(8)AS BYTE = (%00000010, // K
%00000010,
%00000010,
%00000011,
%00000011,
%00000011,
%00000010,
%00000010)
CONST K2(8)AS BYTE = (%00000100, // K
%00000100,
%00000101,
%00000110,
%00000110,
%00000101,
%00000100,
%00000100)
CONST K3(8)AS BYTE = (%00001000, // K
%00001001,
%00001010,
%00001100,
%00001100,
%00001010,
%00001001,
%00001000)
CONST K4(8)AS BYTE = (%00010000, // K
%00010010,
%00010100,
%00011000,
%00011000,
%00010100,
%00010010,
%00010001)
CONST K5(8)AS BYTE = (%00100000, // K
%00100100,
%00101000,
%00110000,
%00110000,
%00101000,
%00100100,
%00100010)
CONST K6(8)AS BYTE = (%01000000, // K
%01001000,
%01010000,
%01100000,
%01100000,
%01010000,
%01001000,
%01000100)
CONST K7(8)AS BYTE = (%10001000, // K
%10010000,
%10100000,
%11000000,
%11000000,
%10100000,
%10010000,
%10001000)
// variable declaration
'DIM x AS BYTE
DIM x AS BYTE
'DIM indexc AS portc
'dim indexb as byte
'DIM bits AS BYTE
dim k(8) as byte
dim b(8) as byte
// Sub Routines
// Start Of Program
'portc = 0
'portb = 1
SetAllDigital // Make all Pins digital I/O's
TRISC = %00000000 // Make PORTD all outputs
TRISB = %00000000 // Make PORTB all outputs
'index = 7
// Main Loop
WHILE True()
for x = 0 to 7
portc = k0(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k1(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k2(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k3(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k4(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k5(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k6(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
for x = 0 to 7
portc = k7(x)
portb = B_data(x)
delayms(1)
next
portc = %00000000
delayms(50)
WEND // Loop back to the while loop as long as we havent finished.
#include <pic.h> // pic specific identifiers
#define _XTAL_FREQ 20000000 // Xtal speed
__CONFIG(0x37F2); // Config bits
#define ROW_PORT PORTB //
#define ROW_TRIS TRISB
#define COL_PORT PORTC //
#define COL_TRIS TRISC
extern const unsigned char fnt[]; // delclare as external (in another file)
// Required prototypes
void DelayMs(int x), scroll(char dir), invert(void);
void clear(void), display(const char* str);
// Variables
unsigned char pos; // keep tabs on rows
unsigned char leds[8]; // led buffer
unsigned char leds2[8]; // 2nd led buffer
unsigned char pow[] = {1,2,4,8,16,32,64,128}; // power array
void main(void) // program entry
{
char x,y,z,t;
ADCON1 = 0x6;
ROW_TRIS = 0b00000000; // row port as outputs
COL_TRIS = 0b00000000; // col port as outputs
T2CON = 0x16; // setup timer 2
ROW_PORT = 0;
COL_PORT = 0xFF; // setup led array
PR2 = 249; // timer preload value
TMR2IE = 1; // enable timer 2 interrupt
PEIE = 1; // enable peripheral interrupt
GIE = 1; // enableglobal interrupt
pos = 0; // start at beginning
while(1) // endless Loop
{
display("Hello world!!"); // display a message
clear(); // start again
DelayMs(1000);
}
}
void display(const char* str)
{
int addr; // large table (requires an int)
int z; // looping variable
while(*str!=0)
{
addr = ((int)*str++ - 0x20); // locate character in table
addr *= 8; // 8 bytes in each char
for(z=0;z<8;z++)
leds2[z] = fnt[addr+z]; // load em up!!
for(z=0;z<8;z++)
scroll(1); // scroll right.
}
}
void interrupt ISR()
{
if(TMR2IF) // omly do if timeout occured
{
ROW_PORT = 0xff;
COL_PORT = leds[pos]; // Retrive current array
ROW_PORT -= pow[pos]; // Keep powers in table
if(pos++ == 7) pos = 0; // cycle through array buffer
TMR2IF = 0; // clear interrupt
}
}
void clear() // clear buffer
{
char x;
for(x=0;x<8;x++)
leds[x] = 0;
}
void scroll(char dir)
{
char x;
switch (dir)
{
case 0: // scroll left
for(x=0;x<8;x++)
{
if(leds2[x] & 1)
leds[x]+=128;
leds[x] >>= 1;
leds2[x]>>= 1;
}
DelayMs(100);
break;
case 1: // scroll right
for(x=0;x<8;x++)
{
if(leds2[x] & 128)
leds[x]+=1;
leds[x] <<= 1;
leds2[x] <<= 1;
}
DelayMs(100);
break;
case 2: // scroll up
for(x=7;x>0;x--)
leds[x] = leds[x-1];
leds[0] = leds2[7];
for(x=7;x>0;x--)
leds2[x] = leds2[x-1];
leds2[0] = 0;
DelayMs(100);
break;
case 3: // scroll down
for(x=0;x<8;x++)
leds[x] = leds[x+1];
leds2[7] = leds[0];
for(x=0;x<8;x++)
leds2[x] = leds2[x+1];
leds2[7] = 0;
DelayMs(100);
}
}
void DelayMs(int x)
{ // wrapper function for larger delays.
while(x--)
__delay_ms(1);
}
%11111111 %10000000 %01000000 %00100000 %01000000 %10000000 %11111111 %00000000
%11111111 %10001001 %10001001 %10000001 %00000000
%00100010 %01010001 %10001001 %10001010 %01000100 %00000000
%00100010 %01010001 %10001001 %10001010 %01000100 %00000000
%00011111 %00101000 %11001000 %01001000 %00101000 %00011111 %00000000
%00000000
%00111100 %01000010 %10000001 $10000101 %01000110 %00000000
%11111111 %10001001 %10001001 %10000001 %00000000
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?