قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots

   

emad_e.m.s
:: مهندس ::
تاريخ التسجيل: Aug 2009
الدولة: syria
المشاركات: 43
نشاط [ emad_e.m.s ]
قوة السمعة:
قديم 24-05-2014, 12:02 AM المشاركة 25   
افتراضي



نعم بالطبع إبدأ من هنا هذا الموضوع للأخ المهندس ناصر أحمد ستجد به ماتريد وماتحتاج للبدء http://www.qariya.info/vb/showthread.php?t=56529

اعلانات

Emna
:: مهندس ::
تاريخ التسجيل: May 2014
الدولة: Tunisia
المشاركات: 10
نشاط [ Emna ]
قوة السمعة:
قديم 24-05-2014, 12:07 AM المشاركة 26   
افتراضي


شكراً جزيلا سيدي

اعلانات اضافية ( قم بتسجيل الدخول لاخفائها )

Emna
:: مهندس ::
تاريخ التسجيل: May 2014
الدولة: Tunisia
المشاركات: 10
نشاط [ Emna ]
قوة السمعة:
قديم 24-05-2014, 04:18 PM المشاركة 27   
x1 وجدت هذا الكود لكن لم أفهم les instructions


/**************************************
* c4017_matrix module *
**************************************/

/*****************description******************
* This is a simple module that enables the *
* user to make and control a led matrix *
* with size varies from (8x8) to (8x64). *
* The module is prefered to run at 20 MHZ *
* pic microcontroller or 8MHZ AVR(Atmega) *
* microcontrollers *
**********************************************/


/*******************About***********************
* Module: *
* c4017_matrix *
* Author: *
* Ahmed Abd Elazeem Eltabakh *
*
***********************************************/

/*****************Preprocessor******************/


/*************************
* header files *
*************************/
#include "dio.h"

/*************************/


#define PORT_LENGTH 8
#define INITIAL_VALUE 0
#define INVERTED 1
#define NONINVERTED 0
#define SPACE 0xff
#define ADDRESS_SHIFT 0
#define LEFT_TO_RIGHT 0
#define RIGHT_TO_LEFT 1
#define UP 1
#define DOWN 0
#define CUL_NUMBER 64

/**********************MACROS*********************/
#define CLOCK_PULSE dio_set_bit(matrix.clock_port,matrix.clock_bit);di o_clear_bit(matrix.clock_port,matrix.clock_bit)
#define usart_send(data) while(!(TXSTA&(1<<TRMT)));TXSTA|=1<<TXEN;TXREG=dat a;

/****************Api Prototype******************/

void c4017_matrix_init(unsigned char data_port,unsigned char scan_port,unsigned char number_of_blocks,unsigned char clock_port,unsigned char clock_bin);

void c4017_matrix_print_const_text(const unsigned char message[],unsigned char speed,unsigned char on_delay,unsigned char off_delay);

void c4017_matrix_print_text( unsigned char message[],unsigned char speed,unsigned char on_delay,unsigned char off_delay);

void c4017_matrix_print_image(const unsigned char *image_name,int image_size,unsigned char speed,unsigned char on_delay,unsigned char off_delay);

void c4017_matrix_enable(unsigned char address);

void c4017_matrix_print_variable(unsigned char variable,unsigned char position);

void clear_buffer(void);

void delay(unsigned char delay_value);

/*********************************************/

/************************
* global variable *
************************/

struct mat
{
unsigned char data_port;
unsigned char address_port;
unsigned char number_of_matrix_blocks;
unsigned char clock_port;
unsigned char clock_bit;
unsigned char cul_number;
} matrix;


unsigned char buffer_array[CUL_NUMBER];
extern const unsigned char char_map[];
extern const unsigned char numbers_map[50];

/********************************************/

/************************************************** *******************************
* Function name: *
* c4017_matrix_init *
* Function Descrption: *
* This function is used to initialize the microcontroller ports *
* to initialize the matrix *
* Function Input: *
* unsigned char data_port the port which the data will be *
* send to the matrix *
* unsigned char scan_port the port which will control the *
* counter 4017 chips *
* unsigned char number_of_blocks *
* number of blocks forms the matrix *
* the block is 8x8 ,Example *
* if you want to make 8x32 *
* then number_of_blocks=4 *
* unsigned char clock_port The port contains the bin connected*
* to the clk bin (bin 14) in the *
* 4017 chips *
* unsigned char clock_bin The number of bin connected to clk *
* bin in the 4017 chips *
* *
* Function Out: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/

void c4017_matrix_init(unsigned char data_port,unsigned char scan_port,unsigned char number_of_blocks,unsigned char clock_port,unsigned char clock_bin)
{
unsigned char output_bits=INITIAL_VALUE;
matrix.data_port=data_port;
matrix.address_port=scan_port;
matrix.number_of_matrix_blocks = number_of_blocks;
matrix.clock_port=clock_port;
matrix.clock_bit=clock_bin;
matrix.cul_number=matrix.number_of_matrix_blocks<< 3;
output_bits=INITIAL_VALUE;
dio_init_bit_output(matrix.clock_port,matrix.clock _bit);
while(output_bits<PORT_LENGTH)
{
dio_init_bit_output(matrix.data_port,output_bits);
dio_init_bit_output(matrix.address_port,output_bit s);
output_bits++;
}

}


/************************************************** */







/************************************************** *******************************
* Function name: *
* c4017_matrix_enable *
* Function Descrption: *
* This function is used to activate the bin with the input value *
* but the addresses should be in sequence *
* Example (1,2,3,4,5,6,..........) *
* but (2,8,4,6,7,3,6,........)(Random sequence) not Allowed *
* Function Input: *
* unsigned char address The address you want to activate *
* *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/



void c4017_matrix_enable(unsigned char address)
{

address>>=3;
dio_set_port(matrix.address_port,~(1<<address));
CLOCK_PULSE;


}

/************************************************** ******/



/************************************************** *******************************
* Function name: *
* c4017_matrix_print_image *
* Function Descrption: *
* This function is used to print the any constant image (array) *
* Function Input: *
* const unsigned char *image_name pointer to the array name *
* *
* int image_size size of the array *
* unsigned char speed speed of scan (number of show *
* times before shift the bits) *
* *
* unsigned char on_delay delay in instruction cycle used *
* to make the column leds on *
* unsigned char off_delay delay in instruction cycle used *
* to turn the columns leds off *
* before activating the next *
* column to avoid duplication *
* and shadow *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/

void c4017_matrix_print_image(const unsigned char *image_name,int image_size,unsigned char speed,unsigned char on_delay,unsigned char off_delay)
{
unsigned char shift_index=INITIAL_VALUE;
unsigned char show_index=INITIAL_VALUE;
unsigned char show_speed=INITIAL_VALUE;
unsigned int image_pixel=INITIAL_VALUE;
clear_buffer();
for(image_pixel=INITIAL_VALUE;image_pixel<image_si ze+matrix.cul_number;image_pixel++)
{
show_speed=INITIAL_VALUE;
while(show_speed<=speed)
{

shift_index=INITIAL_VALUE;
while(shift_index<matrix.cul_number)
{
dio_set_port(matrix.data_port,SPACE);
delay(off_delay);
c4017_matrix_enable(shift_index);
dio_set_port(matrix.data_port,buffer_array[shift_index]);
delay(on_delay);
if(show_speed==speed&&shift_index<=matrix.cul_numb er-2)
{
buffer_array[matrix.cul_number-1-shift_index]= buffer_array[matrix.cul_number-2-shift_index] ;
}
shift_index++;
}

show_speed++;
}

if(image_pixel<image_size)
buffer_array[0]=~image_name[image_size-1-image_pixel];

else
{
buffer_array[0]=SPACE;
}

}

}

/************************************************** ***/





/************************************************** *******************************
* Function name: *
* c4017_matrix_print_const_text *
* Function Descrption: *
* This function is used to print the any constant array of characters*
* (string) *
* Function Input: *
* const unsigned char message[] the name of the characters array*
* *
* unsigned char speed speed of scan (number of show *
* times before shift the bits) *
* *
* unsigned char on_delay delay in instruction cycle used *
* to make the column leds on *
* unsigned char off_delay delay in instruction cycle used *
* to turn the columns leds off *
* before activating the next *
* column to avoid duplication *
* and shadow *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/

void c4017_matrix_print_const_text(const unsigned char message[],unsigned char speed,unsigned char on_delay,unsigned char off_delay)
{
unsigned char shift_index=INITIAL_VALUE;
unsigned char show_index=INITIAL_VALUE;
unsigned char show_speed=INITIAL_VALUE;
unsigned char number_of_message_char=INITIAL_VALUE;
unsigned char printed_char=INITIAL_VALUE;
unsigned int current_position=INITIAL_VALUE,final_value=INITIAL _VALUE;

clear_buffer();
while(message[number_of_message_char++]);
number_of_message_char--;//count number of characters
for(;printed_char<number_of_message_char;printed_c har++)
{
current_position=message[printed_char]-32;
current_position*=6;
final_value=current_position+6;
for(;current_position<final_value;current_position ++)
{
show_speed=INITIAL_VALUE;
while(show_speed++<=speed)
{

for(shift_index=INITIAL_VALUE;shift_index<matrix.c ul_number;shift_index++)
{
delay(off_delay);
c4017_matrix_enable(shift_index);
dio_set_port(matrix.data_port,buffer_array[shift_index]);
delay(on_delay);
//shift at the last time of show
if(show_speed==speed&&shift_index!=matrix.cul_numb er-1)
{
buffer_array[shift_index] = buffer_array[shift_index+1] ;
}
else if(show_speed==speed&&shift_index==matrix.cul_numb er-1)
buffer_array[matrix.cul_number-1]=SPACE;
dio_set_port(matrix.data_port,SPACE);
}

}

buffer_array[matrix.cul_number-1]=~char_map[current_position];

}

}
//shift to make the space
for(printed_char=0;printed_char<matrix.cul_number; printed_char++)
{
show_speed=INITIAL_VALUE;
while(show_speed++<=speed)
{
for(shift_index=INITIAL_VALUE;shift_index<matrix.c ul_number;shift_index++)
{
delay(off_delay);
c4017_matrix_enable(shift_index);
dio_set_port(matrix.data_port,buffer_array[shift_index]);
delay(on_delay);
if(show_speed==speed&&shift_index!=matrix.cul_numb er-1)
{
buffer_array[shift_index] = buffer_array[shift_index+1] ;
}
else if(show_speed==speed&&shift_index==matrix.cul_numb er-1)
buffer_array[matrix.cul_number-1]=SPACE;
dio_set_port(matrix.data_port,SPACE);
}

}




}

}



/************************************************** ****/





/************************************************** *******************************
* Function name: *
* c4017_matrix_print_text *
* Function Descrption: *
* This function is used to print the any array of characters *
* (string) *
* Function Input: *
* unsigned char message[] the name of the characters array*
* *
* unsigned char speed speed of scan (number of show *
* times before shift the bits) *
* *
* unsigned char on_delay delay in instruction cycle used *
* to make the column leds on *
* unsigned char off_delay delay in instruction cycle used *
* to turn the columns leds off *
* before activating the next *
* column to avoid duplication *
* and shadow *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/


void c4017_matrix_print_text(unsigned char message[],unsigned char speed,unsigned char on_delay,unsigned char off_delay)
{
unsigned char shift_index=INITIAL_VALUE;
unsigned char show_index=INITIAL_VALUE;
unsigned char show_speed=INITIAL_VALUE;
unsigned char number_of_message_char=INITIAL_VALUE;
unsigned char printed_char=INITIAL_VALUE;
unsigned int current_position=INITIAL_VALUE,final_value=INITIAL _VALUE;

clear_buffer();
while(message[number_of_message_char++]);
number_of_message_char--;//count number of characters
for(;printed_char<number_of_message_char;printed_c har++)
{
current_position=message[printed_char]-32;
current_position*=6;
final_value=current_position+6;
for(;current_position<final_value;current_position ++)
{
show_speed=INITIAL_VALUE;
while(show_speed++<=speed)
{

for(shift_index=INITIAL_VALUE;shift_index<matrix.c ul_number;shift_index++)
{
delay(off_delay);
c4017_matrix_enable(shift_index);
dio_set_port(matrix.data_port,buffer_array[shift_index]);
delay(on_delay);
//shift at the last time of show
if(show_speed==speed&&shift_index!=matrix.cul_numb er-1)
{
buffer_array[shift_index] = buffer_array[shift_index+1] ;
}
else if(show_speed==speed&&shift_index==matrix.cul_numb er-1)
buffer_array[matrix.cul_number-1]=SPACE;
dio_set_port(matrix.data_port,SPACE);
}

}

buffer_array[matrix.cul_number-1]=~char_map[current_position];

}

}
//shift to make the space
for(printed_char=0;printed_char<matrix.cul_number; printed_char++)
{
show_speed=INITIAL_VALUE;
while(show_speed++<=speed)
{
for(shift_index=INITIAL_VALUE;shift_index<matrix.c ul_number;shift_index++)
{
delay(off_delay);
c4017_matrix_enable(shift_index);
dio_set_port(matrix.data_port,buffer_array[shift_index]);
delay(on_delay);
if(show_speed==speed&&shift_index!=matrix.cul_numb er-1)
{
buffer_array[shift_index] = buffer_array[shift_index+1] ;
}
else if(show_speed==speed&&shift_index==matrix.cul_numb er-1)
buffer_array[matrix.cul_number-1]=SPACE;
dio_set_port(matrix.data_port,SPACE);
}

}




}
}

/************************************************** ********/




/************************************************** *******************************
* Function name: *
* clear_buffer *
* Function Descrption: *
* This function is used to clear the buffer array *
* Function Input: *
* void *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/


void clear_buffer()
{
unsigned char buffer=INITIAL_VALUE;
while(buffer<matrix.cul_number)
{
buffer_array[buffer++]=SPACE;
}
}

/************************************************** **********/






/************************************************** *******************************
* Function name: *
* delay *
* Function Descrption: *
* This function is used to generate delay *
* Function Input: *
* unsigned char delay_value *
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/


void delay(unsigned char delay_value)
{
volatile unsigned char delay_u;
for(delay_u=0;delay_u++<delay_valueasm{nop};
}

/************************************************** ***********/






/************************************************** *******************************
* Function name: *
* c4017_matrix_print_variable * *
* Function Descrption: *
* This function print numbers *
* Function Input: *
* unsigned char variable the number from(0)to(9) *
* unsigned char position the position of the the number*
* Function Output: *
* Void *
* Created By: *
* Ahmed Eltabakh *
************************************************** *******************************/

void c4017_matrix_print_variable(unsigned char variable,unsigned char position)
{

unsigned char temp_value=INITIAL_VALUE;
c4017_matrix_enable(matrix.cul_number);
position<<=3;
variable*=5;
temp_value=variable+5;
dio_set_port(matrix.data_port,SPACE);
c4017_matrix_enable(position++);
delay(150);
while(variable<temp_value)
{
dio_set_port(matrix.data_port,SPACE);
dio_set_port(matrix.data_port,~numbers_map[variable++]);
c4017_matrix_enable(position++);
delay(150);

}

}


/************************************************/



الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 01:41 AM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)