|
قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots |
أدوات الموضوع |
|
|||||
السلام عليكم لكل أعضاء القريه أنا بحاجه ملحه لشرح هذا الكود، وطبعا الموضوع كان للأخ المهندس أحمدطباخ. كل الشكر و التقدير و مزيد من التقدم. /* Author:Eng/Ahmed Eltabakh (the lion) nickname : the lion data :5/8/2010 Email :lionofengineering*yahoo.com project name : test 8x64 matrix v1.0 About simple prject for testing 2 main led matrix functions 1-text_const_print >> function prints long texts saved in ROM ,the text length depends on the free Rom size 2-text_print >>function prints small texts saved in RAM ,the text lenght depends on the free RAM size this API can be used for printing a message received from the computer using usart protocol or and other protocol */ /* ****************************** * include * ****************************** */ /* ****************************** * define * ****************************** */ #define LOW 0 #define HIGH 1 #define DATA_PIN PORTB.F0 #define DATA_DATA_CLOCK_PIN PORTB.F1 #define DATA_SHOW_CLOCK_PIN PORTB.F2 #define ENABLE_DATA_PIN PORTA.F0 #define ENABLE_DATA_CLOCK_PIN PORTA.F1 #define ENABLE_SHOW_CLOCK_PIN PORTA.F2 /* ****************************** * Global variables * ****************************** */ char binary_array[8],buffer[64]; extern const unsigned char ahmednum[455]; const unsigned char long_message[]= "A microcontroller has on-chip peripherals that" "dramatically decrease the amount of external" "components needed in a design. It may have " "general purpose IO, serial IO,ADC and sometimes even" "special purpose IO pins that support protocol such as" "the I2C bus all built into the chip itself. Typically these " "peripherals present themselves as IO registers to the" "CPU for example, to generate a high signal on an " "output pin, one usually only requires the CPU to write" "a 1 to the corresponding IO register bits." "Some CPU architectures have a separate IO space for" "these registers with special instructions to access" "them. Since there is no such concept as IO space in" "the C language per se, in these cases the C compiler " ; const unsigned char myname[]="Made by >> Engineer / Ahmed Abd ElAzeem Eltabakh ... Email / lionofengineering*yahoo.com " ; /* ****************************** * macros * ****************************** */ void send_data(char data); void convert_to_binary(char number); void transmit_data_to_shift(); void data_data_clock_pulse(); void data_show_clock_pulse(); void flush_and_load(); void enable_data_clock_pulse(); void enable_show_clock_pulse(); void text_print(char text[100],char speed); void clear_the_buffer(); void show_buffer(char scroll_speed); //************************** /************************************************** ********* * Function name: * * send_data * * Function Description: * * The function is used to send the data to * * to the data shift register * * (send the characters) * * Function Input: * * char(data to be send) * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void send_data(char data) { convert_to_binary(data); transmit_data_to_shift(); } /************************************************** ********* * Function name: * * convert_to_binary * * Function Description: * * The function is used to convert any number* * in the decimal or hexdecimal form to the * * binary form ,example convert(0xff)or 255 * * to 0b11111111 * * Function Input: * * char * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void convert_to_binary(char number) { char x; for(x=0;x<8;x++) { binary_array[7-x]=number%2; number=number/2; } } /************************************************** ********* * Function name: * * transmit_data_to_shift * * Function Description: * * The function is used to transmit the data * * converted to binary form to the data * * shift register * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void transmit_data_to_shift() { char x; for(x=0;x<8;x++) { DATA_PIN=binary_array[x]; data_data_clock_pulse(); } data_show_clock_pulse(); } /************************************************** ********* * Function name: * * data_data_clock_pulse * * Function Description: * * The function is used to send a clock * * pulse to the (sh) pin on the data shift * * register * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void data_data_clock_pulse() { DATA_DATA_CLOCK_PIN=LOW; DATA_DATA_CLOCK_PIN=HIGH; } /************************************************** ********* * Function name: * * data_show_clock_pulse * * Function Description: * * The function is used to send a clock * * pulse to the (st) pin on the data shift * * register * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void data_show_clock_pulse() { DATA_SHOW_CLOCK_PIN=LOW; DATA_SHOW_CLOCK_PIN=HIGH; } /************************************************** ********* * Function name: * * enable_data_clock_pulse * * Function Description: * * The function is used to send a clock * * pulse to the (sh) pin on the enable shift * * registers * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void enable_data_clock_pulse() { ENABLE_DATA_CLOCK_PIN=LOW; ENABLE_DATA_CLOCK_PIN=HIGH; } /************************************************** ********* * Function name: * * enable_show_clock_pulse * * Function Description: * * The function is used to send a clock * * pulse to the (st) pin on the enable shift * * registers * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void enable_show_clock_pulse() { ENABLE_SHOW_CLOCK_PIN=LOW; ENABLE_SHOW_CLOCK_PIN=HIGH; } /************************************************** ********* * Function name: * * next_column * * Function Description: * * The function is used to shift the enable * * shift registers one column to right * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void next_column() { ENABLE_DATA_PIN=LOW; enable_data_clock_pulse(); enable_show_clock_pulse(); } /************************************************** ********* * Function name: * * load * * Function Description: * * The function is used to load the enable * * shift registers with one ,or enable the * * first column * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void load() { { ENABLE_DATA_PIN=LOW; enable_data_clock_pulse(); enable_show_clock_pulse(); } { ENABLE_DATA_PIN=HIGH; enable_data_clock_pulse(); enable_show_clock_pulse(); } } /************************************************** ********* * Function name: * * text_const_print * * Function Description: * * The function accept const text then recognize* * the used characters then print it on the * * led matrix * * Function Input: * * const unsigned char *text>>const text name char speed * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void text_const_print(const unsigned char *text,char speed) {char looop; int address,character,number_of_characters,update; //while(1){ number_of_characters=0; while(text[number_of_characters]) { number_of_characters++; } clear_the_buffer(); for(update=0;update<number_of_characters;update++) { address=text[update]-32; address=address*5; for(character=address;character<address+5;characte r++) { // update the buffer with the new characters { for(looop=0;looop<63;looop++) { buffer[looop]=buffer[looop+1]; } buffer[63]=ahmednum[character]; } //show the data saved in the buffer show_buffer(speed); } //shift the buffer for aspace between characters /* { for(looop=0;looop<63;looop++) { buffer[looop]=buffer[looop+1]; } buffer[63]=0; } */ } //the great space in the end of scrolling buffer[63]=0; for(looop=0;looop<63;looop++) { for(character=0;character<64;character++) { buffer[character]=buffer[character+1]; } show_buffer(speed); } //} } /************************************************** ********* * Function name: * * text_print * * Function Description: * * The function accept a text then recognize * * the used characters then print it on the * * led matrix * * Function Input: * * char,char * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void text_print(char text[],char speed) {char number_of_characters,update,looop; int address,character; //while(1){ number_of_characters=0; while(text[number_of_characters]) { number_of_characters++; } clear_the_buffer(); for(update=0;update<number_of_characters;update++) { address=text[update]-32; address=address*5; for(character=address;character<address+5;characte r++) { // update the buffer with the new characters { for(looop=0;looop<63;looop++) { buffer[looop]=buffer[looop+1]; } buffer[63]=ahmednum[character]; } //show the data saved in the buffer show_buffer(speed); } //shift the buffer for aspace between characters /* { for(looop=0;looop<63;looop++) { buffer[looop]=buffer[looop+1]; } buffer[63]=0; } */ } //the great space in the end of scrolling buffer[63]=0; for(looop=0;looop<63;looop++) { for(character=0;character<64;character++) { buffer[character]=buffer[character+1]; } show_buffer(speed); } //} } /************************************************** ********* * Function name: * * clear_the_buffer * * Function Description: * * The function is used to clear the buffer * * array,fill all the array with zer0 * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void clear_the_buffer() { char loop; while(loop<64) { buffer[loop]=0; loop++; } } /************************************************** ********* * Function name: * * show_buffer * * Function Description: * * The function is used to print the data on * * the buffer array on the led matrix * * Function Input: * * void * * Function Output: * * void * * Created By: * * Ahmed ElTabakh * * * ************************************************** *********/ void show_buffer(char scroll_speed) { char show_loop,scroll_times; for(scroll_times=0;scroll_times<scroll_speed;scrol l_times++) { show_loop=0; load(); while(show_loop<64) { send_data(~buffer[show_loop]); delay_us(540); next_column(); send_data(0xff); show_loop++; } } } /*void print_test() { int show,ch=0; for(; ![]() { //flush_and_load(); load(); for(show=ch;show<ch+64;show++) { send_data(~ahmednum[show]); delay_us(540); next_column(); send_data(0xff); } ch++; if(ch==580)ch=0; } } */ void main() { trisb=0; trisa=0; while(1) { text_const_print(myname,1); text_print("testing text print API>then print long text ",1); text_const_print(long_message,1); } } |
اعلانات |
إضافة رد |
![]() |
العلامات المرجعية |
أدوات الموضوع | |
|
جميع الحقوق محفوظة 2017
|