מבוא לשפת C של מיקרו-בקר (PIC16F877)

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Truth Tables and Logic Gates. What are Logic Gates? Logic gates are components used in making logic circuits. Each gate has one or more inputs and produces.
Logic Gates.
Programmable Logic Controllers.
Basic Logic Gate Sayed Mahbub Hasan Amiri Dhaka Residential Model College.
CDA 3100 Recitation Week 10.
Output is G1 BCG Truth Table for ‘B OR C’ Input is B, C.
Full Adder Display. Topics A 1 bit adder with LED display Ripple Adder Signed/Unsigned Subtraction Hardware Implementation of 4-bit adder.
C Examples 1.
C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar.
n-bit comparator using 1-bit comparator
AB 11 22 33 44 55 66 77 88 99 10  20  19  18  17  16  15  14  13  12  11  21  22  23  24  25  26  27  28.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Project Done By: Apurva Patel Vrajesh Patel Swapna Kalakonda.
Lab II Real-Time Embedded Operating System for a SoC System.
Railway Foundation Electronic, Electrical and Processor Engineering.
Railway Foundation Electronic, Electrical and Processor Engineering.
1 CSE 20: Lecture 7 Boolean Algebra CK Cheng 4/21/2011.
Dr. Amr Talaat. #include ; /* this makes the header file for the PIC16f877 ready to be used in the C-class */ #define LED PORTC ; /* defines.
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Arduino Programming Language Chin-Shiuh Shieh ( 謝欽旭 ) Department.
Introduction to Computer Systems and the Java Programming Language.
Quiz What are the results of the following 4-bit bitwise logical operations? NOT OR NOR AND
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs.
Dr. Hoganson CSIS 4381 Input from Port D In this project, we will use port D as input and port A as output, by connecting three input bits of port D to.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
ECE 371 – Unit 9 Interrupts (continued). Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge)
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Data Representation Bits, Bytes, Binary, Hexadecimal.
Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected.
Projects 8051.
Input Interface – Microprocessor
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
1-3 GPIO_Output(LuminaryLibrary) 1.Alter the output current to 4mA 2.Let LED0 turn on but LED 1 turn off. Modify your program in E:\yourname\arm.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Digital Activity work sheet Inputs  Sound  Light  Heat  Slide Switch  Push Switch Output  Light________________  Buzzer______________  Relay_______________.
AND Gate Inputs Output Input A (Switch) Input B (Switch) Output Y (Lamp) 0 (Open) 0 (OFF) A B Lamp.
Bit Manipulation in 'C' 'C' bit operators
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 2 : August 28 webpage:
Introduction to Projects using Microcontroller Md. Khalilur Rhaman Credit: Interface Lab.
Microprocessors A practical approach..
Department of Preparatory Year, Umm Al Qura University
Embedded Systems Programming Examples and Comparison
Logic Gates and Boolean Algebra
Logic Gates.
Lab02 :Logic Gate Fundamentals:
Logic Gates.
European Robotic LABoratory
Digital Signals Digital Signals have two basic states:
Transistor & Voltage Divider
Binary – Octal - Hexadecimal
The 3-Way Light Switch and The If-And-Only-If Statement
Lecture 5 from (Chapter 4, pages 73 to 96)
Week 3 Logic will get you from A to B. Imagination will take you everywhere. Albert Einstein.
Logic Gates.
Introduction to Programming – 4 Operators
Lecture 5 Binary Operation Boolean Logic. Binary Operations Addition Subtraction Multiplication Division.
XOR Function Logic Symbol  Description  Truth Table 
A connectionist model in action
Module 2 Variables, Data Types and Arithmetic
PIC16F887.  1.Microcontroller introducton  2.MPLAB,Hi-tech compilers  3.LED  4.Switches/push buttons  5.7-Segment Display  6.Keypad  7.LCD  8.Timers.
Week 3 Logic will get you from A to B. Imagination will take you everywhere. Albert Einstein.
Digital Logic Design.
A modular robot for use in the RoboSumo lab
Presentation transcript:

מבוא לשפת C של מיקרו-בקר (PIC16F877)

יתרונות שפת C שפת C מקצרת ומפשטת את הכתיבה בצורה מאוד משמעותית וניתן להשיג את המטרות בזמן הרבה יותר קצר. ניתן לטפל בטעויות ביתר קלות. כך נוכל לבנות פרויקטים מעניינים הרבה יותר מהר.

תוכנית ראשונה include <pic.h> main() } TRISD=0xFF; //set PORTD input TRISE=0b0000000; //set PORTE output /*led depend on switch*/ TRISB=0b11111111; //input(default( TRISC=0b00000000; //output RC0=1; //initialing while(1) if(RB0==0) RC0=0; // light is on else RC0=1; // light is off { {

כך נראית התוכנית בסביבת העבודה

נעבור על כמה כללים בסיסיים של שפת C לולאת FOR for(x=0; x<4; x++) } RE1=1; for(x=0; x<7000; x++); RE1=0;

ביטוי מסוג if…..else…. לולאת WHILE RC0=0; // light is on else if(RB0==0) RC0=0; // light is on else RC0=1; // light is off לולאת WHILE while (1) { כאן כותבים את האלגוריתם עצמו. כדי שתוכנית תחזור על עצמה כל הזמן, היא צריכה להיות בלולאה אינסופית. לדוגמה סריקה של הלחצן כמו בתוכנית הפשוטה.

#include>pic.h< פונקציות #include>pic.h< void Init (void); void main () { ADCON1=0x06; TRISA=0x00; TRISD=0x00; Init(); while(1); }

ביטוי DEFINE משתנים #define set 1; #define EN_TRIG ((LCD_EN = 1),(LCD_EN = 0)); משתנים משתנה מסוג unsigned הוא עבור משתנים חיוביים והוא בגודל bit 0 : 255. משתנה מסוג signed הוא עבור משתנים שליליים והוא בגודל -128 : 127 bit

פעולות נומריות פעולה סימון דוגמה תוצאה חיבור + a+b 0x14 חיסור - a-b 0x0E כפל * a*b 0x33 חילוק / b/a 0x05 מודולוס(שארית) % b%a 0x02 and & b&a 0x01 or | b|a 0x13 xor ^ b^a 0x12 הזזה ימינה >> b>>a הזזה שמאלה << b<<a 0x88 increment ++ ++a 0x04 decrement -- --a 0x03 היפוך -a -0x03 השלמה לוגית ~ ~a 0xFC

ביטויים לוגיים פעולה סימון דוגמה תוצאה גדול מ-... < a>b FALSE קטן מ-... > a<b TRUE שווה = a=b גדול או שווה <= a>=b קטן או שווה >= a<=b לא שווה =! a!=b And לוגי && a&&b Or לוגי || a||b השלמה לוגית ! !a