طراح

طراح

زندگی یعنی پژوهش و فهمیدن چیز جدید ( پروفسور حسابی)
طراح

طراح

زندگی یعنی پژوهش و فهمیدن چیز جدید ( پروفسور حسابی)

تبدیل رشته به عدد

برای تبدیل رشته به عدد مجموعه ای از توابع در stdlib.h (در بعضی کامپایلر ها cstdlib.h) تعریف شده که نحوه استفاده شان تقریبا یکسان است، یک پارامتر ورودی دریافت می کنند که همان رشته *char است و خروجی شان یک عدد که البته در هر کدام از این توابع نوع داده خروجی فرق می کند.

تابع ()atoi یک رشته را به عددی از نوع داده int تبدیل می کند که طبیعتا بدون اعشار خواهد بود، مثلا :

char a[] = "1234";
int i = atoi(a);

تابع ()atol یک رشته را به عددی از نوع داده long int تبدیل می کند که آن هم بدون اعشار خواهد بود، مثلا :

char a[] = "123456789";
long int i = atol(a);

تابع ()atof یک رشته را به عددی از نوع داده double تبدیل می کند که عددی اعشاری خواهد بود، مثلا :

char a[] = "1234.56";
double i = atof(a);

تابعی با نام ()strtol می تواند یک رشته را از مبنای عددی مشخصی به معادل عددی در مبنای 10 تبدیل کند،
مثلا یک رشته A3E که در مبنای 16 (هگزادسیمال) است را معادل عددی 2622 تبدیل کند.
پارامتر اول رشته مورد نظر است.
پارامتر دوم اختیاری است و می تواند انتهای رشته عددی را مشخص کند که غالبا با null یا 0 مشخص می شود.
پارامتر سوم مبنای عددی رشته است، مثلا 2 برای باینری (Binary) و 10 برای دسیمال (Decimal) و 8 برای اکتال (Octal) و ... 
خروجی این تابع یک عدد صحیح در مبنای long int است.


مثلا:

char a[] = "A3E";
long int i = strtol(a, 0, 16);

تابعی با نام ()strtod شبیه ()atof است، با این تفاوت که پارامتر اختیاری دوم می تواند انتهای رشته عددی
را مشخص کند که البته عموما با همان مقدار 0 نادیده گرفته می شود.

مثلا :

char a[] = "3.14159";
double i = strtod(a, 0);

تابعی هم با نام ()strtoul شبیه به ()strtol می باشد، فقط فرق شان در این است که strtoul اعداد را بدون علامت
مثبت و منفی (unsigned) محاسبه می کند، یعنی خروجی اش unsigned long int است.

مثلا :

char a[] = "1010011";
unsigned long int i = strtoul(a, 0, 2);



کتابخانه ماژول SIM900 - GSM

مدتی است که کتابخانه ای برای استفاده از ماژول های GSM نوشته ام و در پروژه های مرتبط با gsm  استفاده میکنم. جهت کمک به دوستان و توسعه و بهینه سازی بیشتر توسط سایر اساتید آن را منتشر میکنم.

کتابخانه را به برنامه تان اضافه کنید و :
ماژول را روشن و کانفیگ کنید
پیامک ها را دریافت و بخوانید
پیامک بفرستید
تماس ها را رد کنید
به تماس پاسخ دهید
پیامک فارسی ارسال کنید
شارژ سیم کارت را چک کنید
از وضعیت شبکه مطلع شوید
از وضعیت سیگنال مطلع شوید
اپراتور سیم کارت را تشخیص دهید
هیچ پیامکی را از دست ندهید(صف انتظار پیام)
حذف پیامک های خوانده شده به صورت هوشمند


دانلود راهنما


دانلود کتابخانه atXmega


دانلود کتابخانه aTmega


برای استفاده از کتابخانه در محیط اتمل استودیو از منوی file>advanced   save   option

قسمت Encoding را در حالت Arabic (Windows) - Codepage 1256 قرار دهید


در توسعه و بهینه سازی این کتابخانه شرکت کنید


حق نشرکتابخانه برای designer2013.blogsky.com محفوظ است. از کپی برداری بدون ذکر منبع خودداری کنید


ابوالفضل شاکری

کالیبراسیون اسیلاتور داخلی AVR

در صورتی که از اسیلاتور داخلی میکروهای avr استفاده میکنید. حتما رجیستر OSCCAL اسیلاتور را ابتدای شروع برنامه با مقدار صحیح بارگزاری کنید تا خطای فرکانس حداقل باشد.
برای این کار با استفاده از پروگرمر MKII و نرم افزار اتمل استودیو میتوانید مقدار صحیح کالیبراسیون اسیلاتور برای فرکانس مورد نظر را از ناحیه signature row بخوانید و در آدرسی دلخواه از اییپرام ذخیره کنید سپس ابتدای برنامه مقدار را از اییپرام داخل رجیستر کالیبراسیون اسیلاتور بارگزاری نمایید.

مانند:

OSCCAL = eeprom_read_byte(0);


روش صحیح فعال کردن کامل sprintf

1- سربرگ solution explorer را انتخاب نمایید


2- روی libraies راست کلیک کنید و گزینه add library را انتخاب کنید


3- از پنجره باز شده تیک گزینه libprintf_flt را بزنید و سپس بر روی ok کلیک کنید.


و سپس:


آشنایی بیشتر با محیط اتمل استدیو

آشنایی با محیط ATMEL STUDIO


من تمام برنامه هایم را با اتمل استدیو مینویسم و واقعا برنامه نویسی با این نرم افزار برای من لذت بخش هستش، قوی ترین رابط کاربری برای برنامه نویسی میکروهای avr اتمل استدیو هست و می خواهم یکم بیشتر با محیط برنامه نویسی اتمل استدیو آشنا بشیم.

1-  اگر گزینه view white space را از آدرس edit>advanced>view white space را انتخاب کنید، تمام فاصله هایی که با tab یا space ایجاد شده اند نمایش داده میشوند.


2- اگر گزینه list methods in current file   از    VAssistX را انخاب کنید یا از شرت کات آن استفادده کنید (alt + m) امکان دسترسی سریع به توابع نوشته شده را خواهید داشت. که در برنامه هایی که توابع زیادی دارند، دسترسی به توابع بسیار سریع میشود.




3- اگر که میخواهید بدانید که یک عبارت را در چند جا و چه جاهایی استفاده کرده اید مکان نما را روی آن عبارت قرار دهید و shift+alt+f را فشار دهید یک پنجره پایین صفحه باز میشود که هر کجا از آن عبارت استفاده کرده باشید را برایتان مشخص میکند.


4- برای پرش به سورس یک عبارت مکان نما را روی آن عبارت قرار دهید و از alt+G استفاده کنید.

5- برای تغییر یک عبارت در تمام متن مکان نما را روی آن عبارت قرار دهید و از shift+alt+R استفاده کنید.


6- برای تمام صفحه شدن محیط برنامه نویسی از shift+alt+Enter استفاده کنید.


7- میتوانید مطابق شکل زیر شماره گذاری کنار خط ها را فعال کنید. (tools>options)


8- برای بستن تمام توابع (جمع کردن آنها) ابتدا ctrl+m و سپس ctrl+a را فشار دهید.


Command

Description

General Development, Web

Edit.Copy

Copies the selected item to the Clipboard.

CTRL+C or CTRL+INSERT

Edit.Cut

Deletes the selected item from the file and copies it to the Clipboard.

CTRL+X or SHIFT+DELETE

Edit.CycleClipboardRing

Pastes an item from the Clipboard ring to the cursor location in the file. To paste the next item in the Clipboard ring instead, press the shortcut again.

CTRL+SHIFT+V

Edit.Delete

Deletes one character to the right of the cursor.

DELETE

Edit.Find

Displays the Quick tab of the Find and Replace dialog box.

CTRL+F

Edit.FindAllReferences

Displays the list of references for the selected symbol.

SHIFT+ALT+F

Edit.FindinFiles

Displays the In Files tab of the Find and Replace dialog box.

CTRL+SHIFT+F

Edit.FindNext

Finds the next occurrence of the search text.

F3

Edit.FindNextSelected

Finds the next occurrence of the currently selected text, or the word at the cursor.

CTRL+F3

Edit.FindPrevious

Finds the previous occurrence of the search text.

SHIFT+F3

Edit.FindPreviousSelected

Finds the previous occurrence of the currently selected text, or the word at the cursor.

CTRL+SHIFT+F3

Edit.FindSymbol

Displays the Find Symbol pane of the Find and Replace dialog box.

ALT+F12

Edit.GoToFindCombo

Puts the cursor in the Find/Command box on the Standard toolbar.

CTRL+D

Edit.IncrementalSearch

Activates incremental search. If incremental search is on, but no input is passed, the previous search query is used. If search input has been found, the next invocation searches for the next occurrence of the input text.

CTRL+I

Edit.Paste

Inserts the Clipboard contents at the cursor.

CTRL+V or SHIFT+INSERT

Edit.QuickFindSymbol

Searches for the selected object or member and displays the matches in the Find Symbol Results window.

SHIFT+ALT+F12

Edit.NavigateTo

Displays the Navigate To dialog box.

CTRL+,

Edit.Redo

Repeats the most recent action.

CTRL+Y or SHIFT+ALT+BACKSPACE or CTRL+SHIFT+Z

Edit.Replace

Displays the replace options on the Quick tab of the Find and Replace dialog box.

CTRL+H

Edit.ReplaceinFiles

Displays the replace options on the In Files tab of the Find and Replace dialog box.

CTRL+SHIFT+H

Edit.SelectAll

Selects everything in the current document.

CTRL+A

Edit.StopSearch

Stops the current Find in Files operation.

ALT+F3, S

Edit.Undo

Reverses the last editing action.

CTRL+Z or ALT+BACKSPACE

View.ViewCode

For the selected item, opens the corresponding file and puts the cursor in the correct location.

CTRL+ALT+0

Command

Description

Shortcut

Edit.CharLeft

Moves the cursor one character to the left.

LEFT ARROW

Edit.CharRight

Moves the cursor one character to the right.

RIGHT ARROW

Edit.DocumentEnd

Moves the cursor to the last line of the document.

CTRL+END

Edit.DocumentStart

Moves the cursor to the first line of the document.

CTRL+HOME

Edit.GoTo

Displays the Go To Line dialog box.

CTRL+G

Edit.GoToDefinition

Navigates to the declaration for the selected symbol in code.

ALT+G

Edit.GoToNextLocation

Moves the cursor to the next item, such as a task in the Task List window or a search match in the Find Results window. Subsequent invocations move to the next item in the list.

F8

Edit.GoToPrevLocation

Moves the cursor back to the previous item.

SHIFT+F8

Edit.IncrementalSearch

Starts incremental search. If incremental search is started but you have not typed any characters, recalls the previous pattern. If text has been found, searches for the next occurrence.

CTRL+I

Edit.LineDown

Moves the cursor down one line.

DOWN ARROW

Edit.LineEnd

Moves the cursor to the end of the current line.

END

Edit.LineStart

Moves the cursor to the start of the line.

HOME

Edit.LineUp

Moves the cursor up one line.

UP ARROW

Edit.NextBookmark

Moves to the next bookmark in the document.

CTRL+K, CTRL+N

Edit.NextBookmarkInFolder

If the current bookmark is in a folder, moves to the next bookmark in that folder. Bookmarks outside the folder are skipped.

If the current bookmark is not in a folder, moves to the next bookmark at the same level.

If the Bookmark window contains folders, bookmarks in folders are skipped.

CTRL+SHIFT+K, CTRL+SHIFT+N

Edit.PageDown

Scrolls down one screen in the editor window.

PAGE DOWN

Edit.PageUp

Scrolls up one screen in the editor window.

PAGE UP

Edit.PreviousBookmark

Moves the cursor to the location of the previous bookmark.

CTRL+K, CTRL+P

Edit.PreviousBookmarkInFolder

If the current bookmark is in a folder, moves to the previous bookmark in that folder. Bookmarks outside the folder are skipped.

If the current bookmark is not in a folder, moves to the previous bookmark at the same level.

If the Bookmark window contains folders, bookmarks in folders are skipped.

CTRL+SHIFT+K, CTRL+SHIFT+P

Edit.ReverseIncrementalSearch

Changes the direction of incremental search to start at the bottom of the file and progress toward the top.

CTRL+SHIFT+I

Edit.ScrollLineDown

Scrolls text down one line. Available in text editors only.

CTRL+DOWN ARROW

Edit.ScrollLineUp

Scrolls text up one line. Available in text editors only.

CTRL+UP ARROW

Edit.ViewBottom

Moves to the last visible line of the active window.

CTRL+PAGE DOWN

Edit.ViewTop

Moves to the first visible line of the active window.

CTRL+PAGE UP

Edit.WordNext

Moves the cursor to the right one word.

CTRL+RIGHT ARROW

Edit.WordPrevious

Moves the cursor to the left one word.

CTRL+LEFT ARROW

View.NavigateBackward

Moves to the previously browsed line of code.

CTRL+-

View.NavigateForward

Moves to the next browsed line of code.

CTRL+SHIFT+-

View.NextError

Moves to the next error entry in the Error List window, which automatically scrolls to the affected section of text in the editor.

CTRL+SHIFT+F12

View.NextTask

Moves to the next task or comment in the Task List window.

 


Command

Description

Shortcut

VAssistX.FindReference

Find all references to the marked text.

SHIFT+ALT+F

VAssistX.FindSymbolDialog

Opens the symbols dialog listing all symbols in the project.

SHIFT+ALT+S

VAssistX.GotoImplementation

Go to implementation.

ALT+G

VAssistX.ListMethodsInCurrentFileOpens the list of all methods in the current file.ALT+M
VAssistX.OpenCorrespondingFileOpens the corresponding file (i.e. .h/.c).ALT+O
VAssistX.OpenFileInSolutionDialogDisplays a list of all files in the solution.SHIFT+ALT+O
VAssistX.PasteShows the paste history menu.CTRL+SHIFT+V
VAssistX.RefactorContextMenuShows the refactor context menu.SHIFT+ALT+Q
VAssistX.RefactorRenameShows the rename dialog.SHIFT+ALT+R
VAssistX.ScopeNextJump to next scope.ALT+Down Arrow
VAssitX.ScopePreviousJump to previous scope.ALT+Up Arrow


از برنامه نویسی با ATMEL STUDIO لذت ببرید

توابع کتابخانه ای استاندارد 2

کتابخانه string.h:

1- char *strcat(char *str1,char *str2):

رشته str2 را به انتهای str1  وصل میکند.

2- char *strcatf(char *str1,char  flash *str2):

رشته str2 را که در حافظه فلش قرار دارد به انتهای رشته str1 وصل میکند.

3- char *strncat(char *str1,char *str2, unsigned char n):

رشته str2 را به طول n کارکتر به انتهای رشته str1 وصل میکند.

4- char *strncatf(char *str1,char flash *str2, unsigned char n):

رشته str2 را که در حافظه فلش قرار دارد به طول n کارکتر به انتهای رشته str1 وصل میکند.

5- char *strchr(char *str,char c):

موقعیت اولین کارکتر برابر با c را که در رشته str قرار داشته باشد برمیگرداند.

6- char *strrchr(char *str,char c):

موقعیت آخرین کارکتر برابر با c را که در رشته str قرار داشته باشد برمیگرداند.

7- signed char strcmp(char *str1,char *str2):

دو رشته str1  با str2 را مقایسه میکند و اگر دو رشته با هم برابر باشند خروجی تابع صفر خواهد بود و  در غیر این صورت غیر صفر.

8- signed char strcmpf(char *str1,char flash *str2):

دورشته str1 را که در حافظه فلش قرار دارد را با رشته str2 مقایسه میکند، در صورتی که دو رشته با هم برابر باشند خروجی تابع صفر خواهد بود و در غیر این صورت غیر صفر.

9- signed char strncmp(char *str1,char *str2, unsigned char n):

دورشته str1  را با رشته str2 به تعداد کارکتر مقایسه میکند، در صورتی که دو رشته با هم برابر باشند خروجی تابع صفر خواهد بود و در غیر این صورت غیر صفر.

10- char *strcpy(char *dest,char *src):
رشته src را در رشته dest کپی میکند.
11- char *strcpyf(char *dest,char *src):
رشته src را که در حافظه فلش قرار دارد را در رشته dest کپی میکند.
12- char *strncpy(char *dest,char *src):
رشته src را به طول کارکتر در رشته dest کپی میکند.

ابوالفضل شاکری

توابه کتابخانه ای استاندارد

کتابخانه stdlib.h :

1- int atoi(char *STR):

تبدیل رشته str به عدد اینتجر


2- long int atol (char *STR):

تبدیل رشته str به عدد لانگ اینتجر


3- void itoa (int n,char *STR):

تبدیل عدد اینتجر(n) به رشته عددی


4- void ltoa (long int n,char *STR):

تبدیل عدد لانگ اینتجر (n) به رشته عددی


5- int rand (void)

تولید عدد رندم بین 0 تا 32767



کتابخانه math.h :

1- unsigned char cabs(signed char x):

برگرداندن قدر مطلق عدد از نوع بایت


2- unsigned int abs(int x):

برگرداندن قدر مطلق عدد از نوع اینتجر


3- float fabs(float x):

برگرداندن قدر مطلق عدد از نوع اعشاری



4- signed char cmax(signed char a, signed char b):

برگرداندن بزرگترین عدد بین a و b - عدد از نوع بایت


5- int max(int a,int b):

برگرداندن بزرگتزین عدد بین a و b - عدد از نوع اینتجر


6- long int lmax(long int a,long int b):

برگرداندن بزرگتزین عدد بین a و b - عدد از نوع لانگ اینتجر


7- float fmax(float a,float b):

برگرداندن بزرگتزین عدد بین a و b - عدد از نوع اعشاری


8- signed char cmin(signed char a,signed char b):

برگرداندن کوچکترین عدد بین a و b - عدد از نوع بایت


8- int min(int a,int b):

برگرداندن کوچکترین عدد بین a و b - عدد از نوع اینتجر


9- float fmin(float a,float b):

برگرداندن کوچکترین عدد بین a و b - عدد از نوع اعشاری


ابوالفضل شاکری

سنسور اثر انگشت sm630


نوع ارتباط با میکرو: سریال - 57600bps

تغذیه: 4.3v - 6v

قادر به ذخیره 768 اثر انگشت.

این سنسور از طریق ارسال داده های دستوری در یک پاکت دیتا به فرم هگز با میکرو ارتباط برقرار میکند.

برنامه نمونه ای برای راه اندازی و استفاده از این سنسور برای Mega AVR و Xmega AVR نوشته شده است. برای تهیه آن تماس بگیرید.(09398931522 - شاکری)

سورس برنامه به زبان C و کامپایلر(Atmel Studio) میباشد.


نرم افزار دمو برای خواندن سنسور با کامپیوتر:


لینک دانلود

ابوالفضل شاکری