CHAPITRE 2: ELEMENTS DU LANGAGE MIKROBASIC

' 2.0.1 TOUS LES MOTS DU BASIC :
absolute abs and array as asm begin boolean byte case char chr clear const dim div double else end end. exit float function goto gosub if include in int integer interrupt is loop label mod module message new not or org print procedure program read select sub step string switch symbol then to with word xor
' 2.0.2 TOUS LES MOTS DU PIC 675 :
IRP RP1 RP0 NOT_TO NOT_PD DC GP5 GPIO5 GP4 GPIO4 GP3 GPIO3 GP2 GPIO2 GP1 GPIO1 GP0 GPIO0 GIE PEIE T0IE INTE GPIE T0IF INTF GPIF EEIF ADIF CMIF T1IF TMR1IF TMR1GE T1CKPS1 T1CKPS0 T1OSCEN NOT_T1SYNC TMR1CS TMR1ON COUT CINV CIS CM2 CM1 CM0 ADFM VCFG CHS1 CHS0 GO NOT_DONE GO_DONE ADON NOT_GPPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 EEIE ADIE CMIE T1IE TMR1IE NOT_POR NOT_BOD CAL5 CAL4 CAL3 CAL2 CAL1 CAL0 IOCB5 IOCB4 IOCB3 IOCB2 IOCB1 IOCB0 IOC5 IOC4 IOC3 IOC2 IOC1 IOC0 VREN VRR VR3 VR2 VR1 VR0 WRERR WREN WR RD ADCS2 ADCS1 ADCS0 ANS3 ANS2 ANS1 ANS0 ID0192 ID1193 ID2194 ID3195 INDF TMR0 PCL STATUS FSR FSRP GPIO PCLATH INTCON PIR1 TMR1L TMR1H T1CON CMCON ADRESH ADCON0 OPTION_REG TRISIO PIE1 PCON OSCCAL WPU IOC IOCB VRCON EEDATA EEADR EECON1 EECON2 ADRESL ANSEL

' 2.1 IDENTIFICATEURS (noms des constantes et des variables, des programmes, des procédures, fonctions, modules) ; doivent commencer par une lettre sans accent ou un souligné (_) ; doivent ensuite contenir des lettre sans accent ou un souligné (_) ou une chiffre ; ne peuvent contenir les caractères :
   ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; < > ? , . / | \ '
' mikroB n'est pas sensible aux minuscules/majuscules, mais Ptitrain l'est

' 2.2 OPÉRATEURS (pour assigner des valeurs, les comparer et effectuer des opérations ; les objets manipulés sont des "opérandes" (variables, constantes...). Les opérateurs ont deux opérandes (sauf les 2 opérateurs unaires). Les 4 types sont : arithmétiques ; booléens ; logique (bit à bit) ; comparaison. [Détails en chapitre 3]

' 2.3 EXPRESSIONS
  A = B + C    ' Expression additionne B et C et stocke le résultat
               '   dans la variable A

' 2.4 INSTRUCTIONS. Une instruction détermine l'action à effectuer.
  if Time = 60 then goto Minute end if

' 2.5 TYPES DE DONNÉES
' Type  	   Taille  	Valeurs max
   byte 	   8-bit 	  0 .. 255
   word 	  16-bit 	  0 .. 65535
   Types structurés : l' array (tableau) et l string (chaîne)

' 2.6 CONSTANTES. Ne peut changer dans tout le programme. Ne consomme pas de mémoire.
   const A = 56           ' 56  en décimal
   const B = $0F          ' 15  en hexadecimal
   const C = %10001100    ' 140 en binary

' 2.7 VARIABLES. Peuvent changer durant le programme. Doivent être déclarées avant toute utilisation.
  dim Temperature as byte ' Déclare la var temperature comme byte (octet)
  dim Voltage as word     ' Déclare la var voltage comme word (16 bits)

' 2.8 SYMBOLS. possibilité de remplacer une expression par un alias afin d'améliorer la lisibilité (p. ex. "haut-parleur" au lieu "PORTB.5")

  symbol Maximum = 234                   ' Alias d'une variable
  symbol PORT = PORTB                    ' Alias d'un registre
  symbol Delai1seconde = delay_ms (1000) ' Alias d'une procédure

' 2.10 COMMENTAIRES. Remarques dans le programme, ne sont pas prises en compte par le Basic, ne consomment pas de mémoire (mettez-en plein). Commencent par une apostrophe. Pas plus d'une ligne.


' 2.11 LABELS (ÉTIQUETTES) : marquent des portions de programmes afin d'y sauter (comenceront souvent par ET_ avec un souligné)
  ET_AttenteUneSeconde:       ' Déclaration adu label avec un deux-points
  goto ET_AttenteUneSeconde   ' Saut vers le label

' 2.12 Procedures and Functions
' 2.13 Modules








' ÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷

CHAPTER 3: OPERATORS
' Introduction
' 3.1 Arithmetic Operators
' 3.2 Boolean Operators
' 3.3 Logical (Bitwise) Operators
' 3.4 Relation Operators (Comparison Operators)
CHAPTER 4: CONTROL STRUCTURES
' Introduction
' 4.1 Conditional Statements
' 4.1.1 IF..THEN Statement
' 4.1.2 SELECT..CASE Statement
' 4.1.3 GOTO Statement
' 4.2 Loops
' 4.2.1 FOR Statement
' 4.2.2 DO..LOOP Statement
' 4.2.3 WHILE Statement
' 4.3 ASM Statement
CHAPTER 5: BUILT-IN AND LIBRARY ROUTINES
'  Introduction
' 5.1 Built-in Routines
' 5.1.1 SetBit

' 5.1.1 SetBit – Sets the specified bit
setbit ( PORTB, 2 )  ' Met à "1" le bit 2 du port B

' 5.1.2 ClearBit ' Clears the specified bit 
clearbit ( PORTB, 2 )  ' Met à "0" le bit 2 du port B

' 5.1.3 TestBit
' 5.1.4 Lo
' 5.1.5 Hi
' 5.1.6 Higher
' 5.1.7 Highest

' 5.1.8 delay_us
' SP qui crée une pause logicielle de durée en microsecondes (word 0..65535)
delay_us ( 1000 )  ' Pause de 1000 microsecondes

' 5.1.8 delay_ms
' SP qui crée une pause logicielle de durée en millisecondes (word 0..65535)
delay_ms ( 500 )  ' Pause de une demi-seconde


' 5.1.10 Inc
' 5.1.11 Dec
' 5.1.12 Length
' 5.2 Library Routines
' 5.2.1 Numeric Formatting
' 5.2.1.1 ByteToStr
' 5.2.1.2 WordToStr
' 5.2.1.3 ShortToStr
' 5.2.1.4 IntToStr
' 5.2.1.5 Bcd2Dec
' 5.2.1.6 Dec2Bcd
' 5.2.1.7 Bcd2Dec16
' 5.2.1.8 Dec2Bcd16
' 5.2.2 ADC Library
' 5.2.2.1 ADC_read
' 5.2.6 EEPROM Library
' 5.2.6.1 EEPROM_Read
' 5.2.6.2 EEPROM_Write
' 5.2.7 Flash Memory Library
' 5.2.7.1 Flash_Read
' 5.2.7.2 Flash_Write
' 5.2.8 I2C Library
' 5.2.8.1 I2C_Init
' 5.2.8.2 I2C_Start
' 5.2.8.3 I2C_Repeated_Start
' 5.2.8.4 I2C_Rd
' 5.2.8.5 I2C_Wr
' 5.2.8.6 I2C_Stop
' 5.2.9 LCD Library
' 5.2.9.1 LCD_Init
' 5.2.9.2 LCD_Config
' 5.2.9.3 LCD_Chr
' 5.2.9.4 LCD_Chr_CP
' 5.2.9.5 LCD_Out
' 5.2.9.6 LCD_Out_CP
' 5.2.9.7 LCD_Cmd
' 5.2.13 PWM Library
' 5.2.13.1 PWM_Init
' 5.2.13.2 PWM_Change_Duty
' 5.2.13.3 PWM_Start
' 5.2.13.4 PWM_Stop
' 5.2.18 Software I2C Library
' 5.2.18.1 Soft_I2C_Config
' 5.2.18.2 Soft_I2C_Start
' 5.2.18.3 Soft_I2C_Write
' 5.2.18.4 Soft_I2C_Read
' 5.2.18.5 Soft_I2C_Stop
' 5.2.21 Sound Library
' 5.2.21.1 Sound_Init
' 5.2.21.2 Sound_Play
' 5.2.22 Trigonometry Library
' 5.2.22.1 SinE3
' 5.2.22.2 CosE3
' 5.2.23 Utilities
' 5.2.23.1 Button
CHAPTER 6: EXAMPLES WITH PIC INTEGRATED PERIPHERALS
' Introduction
' 6.1 Interrupt Mechanism
' 6.2 Internal AD Converter
' 6.3 TMR0 Timer
' 6.4 TMR1 Timer
' 6.5 PWM Module
' 6.6 Hardware UART module (RS-232 Communication)
CHAPTER 7: EXAMPLES WITH DISPLAYING DATA
' Introduction
' 7.1 LED Diode
' 7.2 Seven-Segment Display
' 7.3 LCD Display, 4-bit and 8-bit Interface
' 7.4 Graphical LCD
' 7.5 Sound Signalization
CHAPTER 8: EXAMPLES WITH MEMORY AND STORAGE MEDIA
' Introduction
' 8.1 EEPROM Memory
' 8.2 Flash Memory
' 8.3 Compact Flash
CHAPTER 9: COMMUNICATIONS
' Introduction
' 9.1 USART and Software UART
' 9.2 SPI and Software SPI
' 9.3 I2C and Software I2C
' 9.4 Manchester Code
' 9.5 RS485
' 9.6 OneWire
' 9.7 CAN & CANSPI
APPENDIX A: MIKROBASIC IDE
' Introduction
' A.1 Installation of mikroBasic
' A.2 First Contact with mikroBasic
' A.3 Creating First Project
