برنامج تحريك حرفين :
الإطار الأول : نبدأ بالإطار الأول فارغ كحالة :
كود:
{0x00,0x00,0x00,0x00,0x00}, //Frame 1
الإطار الثانى : يبدأ ظهور أو عامود بالإطار الثانى عن طريق نقل (إزاحة) بياناته (0x40) :
كود:
{0x00,0x00,0x00,0x00,0x40},
الإطار الثالث : نقل مع إزاحة فى الإطار السابق :
كود:
{0x00,0x00,0x00,0x40,0x40},
وهكذا نحصل على المصفوفة :
كود:
{0x00,0x00,0x00,0x00,0x00},//13 frames X 5 columns
{0x00,0x00,0x00,0x00,0x40},
{0x00,0x00,0x00,0x40,0x40},
{0x00,0x00,0x40,0x40,0x7F},
{0x00,0x40,0x40,0x7F,0x40},
{0x40,0x40,0x7F,0x40,0x40},
{0x40,0x7F,0x40,0x40,0x00},
{0x7F,0x40,0x40,0x00,0x7F},
{0x40,0x40,0x00,0x7F,0x49},
{0x40,0x00,0x7F,0x49,0x49},
{0x00,0x7F,0x49,0x49,0x41},
{0x7F,0x49,0x49,0x41,0x41},
{0x49,0x49,0x41,0x41,0x00},
البرنامج
كود:
//Program for PIC16F628A.
// Two-dimensional array declaration
const unsigned short int Array_Data [13][5]={ //10 rows X 5 Column
{0x00,0x00,0x00,0x00,0x00},//13 frames X 5 columns
{0x00,0x00,0x00,0x00,0x40},
{0x00,0x00,0x00,0x40,0x40},
{0x00,0x00,0x40,0x40,0x7F},
{0x00,0x40,0x40,0x7F,0x40},
{0x40,0x40,0x7F,0x40,0x40},
{0x40,0x7F,0x40,0x40,0x00},
{0x7F,0x40,0x40,0x00,0x7F},
{0x40,0x40,0x00,0x7F,0x49},
{0x40,0x00,0x7F,0x49,0x49},
{0x00,0x7F,0x49,0x49,0x41},
{0x7F,0x49,0x49,0x41,0x41},
{0x49,0x49,0x41,0x41,0x00},
};
//Variables declaration
unsigned short Display_column , repeat ,Frame_no;
//Functions
void Reset(void){
PORTA.F1=1;// Reset 4017
PORTA.F1=0;
}
void Clk(void){
PORTA.F0=1; // Colck the 4017 for next column
PORTA.F0=0;
}
void main(){ //Main function
CMCON=0x7; // Turn comparators off and enable pins for I/O functions
TRISA=0;
TRISB=0;
while(1){
for(Frame_no=0;Frame_no<13;Frame_no++){ //repeat for 10 frames
كود:
for(repeat=0;repeat<50;repeat++){ //repeat frame display=time=speed
Reset();
for(Display_column =0; Display_column <5; Display_column ++){ // }//each frame loop
PORTB= Array_Data[Frame_no][ Display_column];
Delay_ms(1); // output port and call DELAY
PORTB=0; // Turn off the output before loading the next
Clk(); // value into the port to prevent "Mirroring" on the display
}//end of each frame
}//end of repeat
}//end of frames
}//endless loop
}//main loop
|