Escolar Documentos
Profissional Documentos
Cultura Documentos
Introducccion
tic
a/
Les propongo un reto constructivo, Mostremos las diferentes maneras de hacer un programa, asi veremos los estilos de
programacion y la sintaxis de diferentes lenguajes de programacion y nos realimentaremos entre todos, no se preocupen
empezamos desde cero!! y sobre todo NADIE TIENE LA RAZON, al menos en terminos de funcionalidad !! ( procuren
poner una linea indicando la salida del compilador (nombre del compilador) para ver el porcentaje de memoria/codigo
usado ) Un ejemplo cada semana asi dejamos 5 dias un tema y luego sera compilado en un pdf y subido al grupo
Enunciado
ro
ni
ca
yr
o
bo
Las n formas de prender y apagar un led fout=1Hz. microcontrolador a usar: 16F1824. (si usas otra cosa, especificalo
en tu codigo) puedes usar un retardo del compilador si quieres.
Codigos de ejemplo
3.1
XC8
4
5
6
7
8
9
10
ct
s/
ele
11
12
13
void main(void){
config_hw();
while(1){
14
16
18
void config_hw(void){
20
21
bo
22
23
TRISA = 0X00;
OSCCON = 0b01101000 ; // intosc -> 1Mhz
ANSELA = 0;
LATA=0;
ce
24
17
19
ok
.co
m
15
/g
ro
up
w.
fa
ww
***********************************************
Logfile:
***********************************************
Microchip MPLAB XC8 C Compiler V1.32-Part Support Version:1.32(A)-Copyright(C)2014 Microchip Technology Inc.
Memory Summary:
Program space used 1Eh (30) of 1000h words ( 0.7%)
Data space used 4h ( 4) of 100h bytes ( 1.6%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Data stack space used 0h ( 0) of F0h bytes ( 0.0%)
Configuration bits used 2h ( 2) of 2h words (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
3 Codigos de ejemplo
3.2
1
2
3
Proton Compiler
***Led off on
;***Pic =16f824
;***Lenguaje = basic ;***Copilador = ;***proton ide
;***Autor = ;Alexander Florez. ;***Bogota colombia ;- 2014
8
9
10
11
12
13
14
15
16
3.3
tic
a/
Device =16f824
Xtal = 4
Trisb = %00000000
Portb = %00000000
Symbol led = Portb.0
Loop:
Led = 1
Delayms 200
Led = 0
Delayms 200
Goto loop
;End
bo
ro
ni
ca
yr
o
AVR Bascom
3
4
5
6
7
8
9
10
ok
.co
m
11
****************************************************
micro= Attiny24 lengaje= basic compilador= Bascom 2.7.5
****************************************************
$regfile = "attiny24.dat"
$crystal = 1000000
Ddrb.0 = 1 : Portb.0 = 0
Do
Toggle Portb.0
Waitms 500
Loop
End
s/
ele
/g
ro
up
ct
nota del autor: Yo uso avrs, y tome uno de caracteristicas similares, el attiny24, cristal de 20mHz, 2kb, 14 pines.
w.
fa
ce
bo
microchip assembler
ww
3.4
1
2
3
4
5
6
7
8
9
;**********************************************************************
; Filename: P16_LedBlinkAsm.asm *
; Date: 04/08/2014 *
; File Version: V1 *
; Author: Ing. Jos Manuel Alvarado *
; Company: ELECTRONICA Y ROBOTICA *
;**********************************************************************
; Notes: *
; Cambia el led de estado utilizando una interrupcion de 0.5s *
3 Codigos de ejemplo
10
11
12
13
;**********************************************************************
list p=16f1824 ; directiva de lista para este microcontrolador
#include <p16f1824.inc> ; definicion de registros para el pic16f
;Palabras de configuracion para este ejemplo
14
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
tic
a/
ww
61
bo
24
ro
ni
ca
yr
o
23
ct
22
s/
ele
21
/g
ro
up
20
ok
.co
m
19
bo
18
ce
17
__CONFIG _CONFIG1,_FOSC_INTOSC&_WDTE_OFF&_PWRTE_ON&_BOREN_ON&_FCMEN_OFF&_IESO_OFF&_MCLRE_OFF&_CLKOUTEN_OFF
__CONFIG _CONFIG2, _LVP_OFF
;**********************************************************************
ORG 0x000 ; vector de reset
goto main ; va al inicio del programa
;Vector de interrupcion de la familia PIC16XXX
ORG 0x004
;Rutina de interrupcion
;Cambio de estado en el pin RA0
banksel LATA
movlw 0x01
xorwf LATA,F
;Vuelve a cargarcontador de timer1 para desbordamiento a 0.5S, el periodo de cambio de estado es 1s
banksel TMR1
movlw 0xF7
movwf TMR1L
movlw 0xC2
movwf TMR1H
bcf PIR1,TMR1IF
;termina interrupcion
retfie ; regresa de interrupcion
main
;preparara portA para usar como led el pin RA0
banksel PORTA
clrf PORTA
banksel LATA
clrf LATA
banksel TRISA
clrf TRISA
banksel ANSELA
clrf ANSELA
;configuracion del oscilador interno a 1MHz
banksel OSCCON
movlw 0x58
movwf OSCCON
;El timer 1 funciona con un preescaler de 8, utiliza como fuente de reloj, el reloj de instrucciones
banksel TMR1
movlw 0x31
movwf T1CON
movlw 0xF7
movwf TMR1L
movlw 0xC2
movwf TMR1H
bcf PIR1,TMR1IF
banksel PIE1
bsf PIE1,TMR1IE;habilita interrupciones
movlw 0xC0
movwf INTCON
main_loop
;puede poner otro codigo aqui
;el codigo que ejecute en esta parte de programa
;solo sera interrumpido por el desbordamiento del timer1
goto main_loop
END
fa
16
w.
15
62
63
64
65
66
67
68
3 Codigos de ejemplo
tic
a/
***********************************************
Logfile:
***********************************************
Microchip MPASM V5.57
Copyright (C) 2014 Microchip Technology Inc.
Proton Compiler
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ct
s/
ele
****************************************************************
* Name : Proton IDE *
* Author : Jacobo Sierra Arellanes, Oaxaca, Mxico *
* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 04/08/2014 *
* Canal : https://www.youtube.com/user/siaj881108hocrrc05/videos *
Device = 16F1824
Xtal 4
TRISA=0
PORTA=0
Inicio:
PORTA=1
DelayMS 1000
PORTA=0
DelayMS 1000
GoTo Inicio
End
/g
ro
up
ok
.co
m
ro
ni
ca
yr
o
3.5
bo
Memory Summary:
Program space used 27h (39) of 1000h words ( 0.9%)
Data space used 0h ( 0) of 100h bytes ( 0%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Data stack space used 0h ( 0) of F0h bytes ( 0.0%)
Configuration bits used 2h ( 2) of 2h words (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
bo
w.
fa
ce
*****************************************************************************
* Notes : 4 variable bytes used from possible 240 (1.67%) *
* : 61 program bytes used from possible 4096 (1,49%) *
*****************************************************************************
XC8
ww
3.6
1
2
3
4
5
6
7
8
9
/*********************************************************************
* File: Blink LED
* Author: Pedro Snchez (MrChunckuee) Electronica&Robotica
* Blog: http://mrchunckuee.blogspot.com/
* Email: mrchunckuee.psr@gmail.com
* Notas: Cambia es estado de LED_STATUS cada 0.5 segundos
* Fosc=4MHz, RA0=LED_STATUS, MCRL = +VCC
* IDE: MPLAB X, Compilador: XC8
3 Codigos de ejemplo
10
11
12
13
#include <xc.h>
14
18
19
20
21
22
23
24
25
26
27
28
29
tic
a/
17
bo
16
ro
ni
ca
yr
o
15
30
31
32
35
//Funciones utilizadas
void MCU_Init(void);
s/
ele
34
ct
33
36
38
39
40
41
42
43
void main(void){
MCU_Init();
while(1){
LED_STATUS ^= 1;
__delay_ms(500);
}
}
/g
ro
up
37
44
46
47
48
49
50
51
52
ce
bo
53
void MCU_Init(void){
OSCCONbits.IRCF3=1;//
OSCCONbits.IRCF2=1;//
OSCCONbits.IRCF1=0;//
OSCCONbits.IRCF0=1;//Oscilador interno a 4MHz
ANSELA=0x00;//PORTA como digital
TRISA=0x00;//RA0 como salida
LED_STATUS=0;//Limpio RA0 antes de cargar un valor
}
ok
.co
m
45
fa
ww
w.
/************************************************************/
Memory Summary:
Program space used 27h ( 39) of 1000h words ( 1.0%)
Data space used 5h ( 5) of 100h bytes ( 2.0%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Data stack space used 0h ( 0) of F0h bytes ( 0.0%)
Configuration bits used 2h ( 2) of 2h words (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
3.7
1
/*********************************
3 Codigos de ejemplo
2
3
4
5
6
7
8
11
12
13
tic
a/
9
10
/* PUERTOS */
#byte PortA= 0x0C
#byte PortC= 0x0E
#bit led= 0x0C.0
16
17
18
/* PROGRAMA PRINCIPAL */
void main (void){
set_tris_a(0b00000000);
set_tris_c(0b00000000);
ro
ni
ca
yr
o
15
bo
14
19
20
21
portA=0;
portC=0;
22
25
26
27
do{
led=0;
delay_ms(500);
led=1;
delay_ms(500);
ct
24
s/
ele
23
28
30
31
}
while(true);
}
/g
ro
up
29
;**********************************************************************
; Filename: P16_LedBlinkAsm2.asm *
; Date: 05/08/2014 *
; File Version: V2 *
; Author: Ing. Jos Manuel Alvarado *
; Company: ELECTRONICA Y ROBOTICA *
;**********************************************************************
; Notes: *
; Cambia el led de estado utilizando retardos por software *
;**********************************************************************
list p=16f1824 ; directiva de lista para este microcontrolador
#include <p16f1824.inc> ; definicion de registros para el pic16f
ww
microchip assembler
w.
3.8
2
3
4
5
6
7
8
9
10
11
12
fa
ce
bo
ok
.co
m
*******************************************************
Compilador CCS v4.140
ROM:
58(1%)
58(1%) including unused fragments
0 Average locations per line
6 Average locations per statement
RAM:
5(2%) at main () level
17(7%) worst case
*******************************************************
3 Codigos de ejemplo
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
tic
a/
19
bo
18
ro
ni
ca
yr
o
17
ct
16
s/
ele
15
/g
ro
up
14
ok
.co
m
13
55
bo
END
ce
56
fa
ww
w.
***********************************************
Logfile:
***********************************************
Microchip MPASM V5.57
Copyright (C) 2014 Microchip Technology Inc.
Memory Summary:
Program space used 27h (26) of 1000h words ( 0.6%)
Data space used 0h ( 2) of 100h bytes ( 0.78%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Data stack space used 0h ( 0) of F0h bytes ( 0.0%)
Configuration bits used 2h ( 2) of 2h words (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)