practicas_mikrobasic

7
 main: ' Main program TRISA = 0 ' Configuro como salidas el puerto A PORT A.0 = ' A!" "O #"C!#"TRO COMO PO"#R A$IAS SO$O #$ C$ASICO S%M&O$  #$A %(MS)*0 0+ ' A,!I !SAMOS #" $!-AR # PA !S# #" P&P $A I"STR!CCIO" #$A%(MS % O&/IAM#"T# #S MI$IS#-!"OS  PORTA.0 = 0  #$A%(MS)*00+  -OTO MAI" end. ' POR "O PO"#R #S# P!"TO "O M# COMPI$O $A PRIM#RA /# 1111111111111111111111111111111111 program Practica2 ' Programa de luces intercalacio n de leds ' eclarations section main: ' Main program TRIS&=0 'puerto & como salida PORT&=0 turn:  #$A%(MS )*00+  PORT& = "OT PORT& 'in3ierte el 3alor de los 4its del puerto  -OTO turn end. 5111111111111111111111111111111 program Practica6 ' 7uego de luces mane7o de arra8 8 for ' eclarations section dim luces as 48te 9; dim i as 48te main:  TRIS&=0  luces90; = <000000  luces9; = <000000  luces92; = <000000  luces96; = <000000  P: i=0  for i=0 to 6  PORT&= luces 9i;  dela8(ms )00+ 'retard o de .seg  ne1t i  for i=2 to 0 step  PORT&= luces 9i;

Upload: renatoromero74

Post on 05-Nov-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

main: ' Main programTRISA = 0 ' Configuro como salidas el puerto APORTA.0 = 1 ' AUN NO ENCUENTRO COMO PONER ALIAS SOLO EL CLASICO SYMBOL DELAY_MS(500) ' AQUI USAMOS EN LUGAR DE PAUSE EN PBP, LA INSTRUCCION DELAY_MS Y OBVIAMENTE ES MILISEGUNDOS PORTA.0 = 0 DELAY_MS(500) GOTO MAINend. ' POR NO PONER ESE PUNTO NO ME COMPILO LA PRIMERA VEZ

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

program Practica2 ' Programa de luces, intercalacion de leds

' Declarations section

main:' Main program TRISB=0 'puerto B como salidaPORTB=0

turn: DELAY_MS (500) PORTB = NOT PORTB 'invierte el valor de los bits del puerto GOTO turnend.

Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

program Practica3 ' juego de luces, manejo de array y for

' Declarations section dim luces as byte [4]dim i as byte

main: TRISB=0 luces[0] = %10000001 luces[1] = %01000010 luces[2] = %00100100 luces[3] = %00011000 P: i=0 for i=0 to 3 PORTB= luces [i] delay_ms (100) 'retardo de .1seg next i for i=2 to 0 step -1 PORTB= luces [i] delay_ms (100) next i GOTO Pend.

Xxxxxxxxxxxxxxxxxxxx

program Practica4 ' Juego de luces, uso del for

' Declarations section DIM X AS BYTE

MAIN: ' Main program TRISB = 0 P: X=0 FOR X=0 TO 7 PORTB.X=1 DELAY_MS(500) NEXT X

FOR X=7 TO 0 STEP -1 PORTB.X=0 DELAY_MS(500) NEXT X GOTO PEND.

Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

program PRACTICA5 ' Programa mezcla de luces con subrutinas NO FUNCIONA

' Declarations section

include "luces" 'se asignan los sub procedimientos a aplicarinclude "juego_de_luces"main: TRISA=1 TRISB=0 PORTB=0 G: if PORTA=0 then turn 'llamado de sub procedimiento else play end if goto Gend.

module luces sub procedure turn () turn: PORTB = NOT PORTB 'invierte el valor de los bits del puerto DELAY_MS (500) end subend.

module juego_de_luces sub procedure play () dim luces as byte [4] dim i as byte luces[0] = %10000001 luces[1] = %01000010 luces[2] = %00100100 luces[3] = %00011000 P: i=0 for i=0 to 3 PORTB= luces [i] delay_ms (100) 'retardo de .1seg next i for i=2 to 0 step -1 PORTB= luces [i] delay_ms (100) next i PORTB=0 end subend.

Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

program Practica6 ' Programa para probar interruptores

' Declarations section

main:' Main program TRISA = 0 ' Configuro como salidas el puerto A TRISB = 1 ' Configuro como ENTRADAS el puerto B IF (PORTB.0 = 0) and (PORTB.1 = 0) THEN PORTA.0 = 1 ' AUN NO ENCUENTRO COMO PONER ALIAS SOLO EL CLASICO SYMBOL DELAY_MS(500) ' AQUI USAMOS EN LUGAR DE PAUSE EN PBP, LA INSTRUCCION DELAY_MS Y OBVIAMENTE ES MILISEGUNDOS PORTA.0 = 0 DELAY_MS(500) END IF IF (PORTB.0 = 0) and (PORTB.1 = 1) THEN PORTA.0 = 1 ' AUN NO ENCUENTRO COMO PONER ALIAS SOLO EL CLASICO SYMBOL DELAY_MS(1000) ' AQUI USAMOS EN LUGAR DE PAUSE EN PBP, LA INSTRUCCION DELAY_MS Y OBVIAMENTE ES MILISEGUNDOS PORTA.0 = 0 DELAY_MS(1000) END IF IF (PORTB.0 = 1) and (PORTB.1 = 0) THEN PORTA.0 = 1 ' AUN NO ENCUENTRO COMO PONER ALIAS SOLO EL CLASICO SYMBOL DELAY_MS(1500) ' AQUI USAMOS EN LUGAR DE PAUSE EN PBP, LA INSTRUCCION DELAY_MS Y OBVIAMENTE ES MILISEGUNDOS PORTA.0 = 0 DELAY_MS(1500) END IF IF (PORTB.0 = 1) and (PORTB.1 = 1) THEN PORTA.0 = 1 ' AUN NO ENCUENTRO COMO PONER ALIAS SOLO EL CLASICO SYMBOL DELAY_MS(2000) ' AQUI USAMOS EN LUGAR DE PAUSE EN PBP, LA INSTRUCCION DELAY_MS Y OBVIAMENTE ES MILISEGUNDOS PORTA.0 = 0 DELAY_MS(2000) END IF GOTO mainend. ' POR NO PONER ESE PUNTO NO ME COMPILO LA PRIMERA VEZ

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

main:' Main program manejo de entrada de bits de los puertos NO FUNCIONA TRISB = %11111111 TRISA = %11100000 PORTA = %00000000 WHILE TRUE IF PORTB.0 = 1 THEN PORTA.0 = 1 DELAY_MS(500) END IF

IF PORTB.1 = 1 THEN PORTA.1 = 1 DELAY_MS(500) END IF IF PORTB.2 = 1 THEN PORTA.2 = 1 DELAY_MS(500) END IF IF PORTB.3 = 1 THEN PORTA.3 = 1 DELAY_MS(500) END IF

IF PORTB.4 = 1 THEN PORTA.4 = 1 DELAY_MS(500) END IF IF (PORTA.5 = 1) OR (PORTA.6 = 1) OR (PORTA.7 = 1) THEN PORTB = 0 END IF DELAY_MS(100) WEND GOTO mainend.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

program practica9

main:' Main program manejo de entrada de bits de los puertos

TRISB = %11111111 TRISA = %00000000 PORTA = %00000000 cmcon = 7

P:

IF PORTB.0 = 1 THEN PORTA.0 = 1 DELAY_MS(500) END IF

IF PORTB.1 = 1 THEN PORTA.1 = 1 DELAY_MS(500) END IF

IF PORTB.2 = 1 THEN PORTA.2 = 1 DELAY_MS(500) END IF

IF PORTB.3 = 1 THEN PORTA.3 = 1 DELAY_MS(500) END IF

IF PORTB.4 = 1 THEN PORTA.4 = 1 DELAY_MS(500) END IF

IF PORTB.5 = 1 THEN PORTA = 0 END IF

DELAY_MS(100) GOTO P GOTO mainend.

Xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

HID Library Exampleprogram HID_Read_Write_Polling

dim cnt,kk as bytedim readbuff as byte[64] absolute 0x500 ' Buffers should be in USB RAMdim writebuff as byte[64] absolute 0x540

main: ADCON1 = ADCON1 or 0x0F ' Configure all ports with analog function as digital CMCON = CMCON or 7 ' Disable comparators HID_Enable(@readbuff,@writebuff) ' Enable HID communication while TRUE ' USB servicing is done inside the while loop USB_Polling_Proc() ' Call this routine periodically kk = HID_Read() if (kk 0) then for cnt=0 to 63 writebuff[cnt]=readbuff[cnt] next cnt HID_Write(@writebuff,64) end if wendend.Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx