Practicas Con MC68HC908QY4
-
Upload
abel-perez -
Category
Documents
-
view
198 -
download
1
Transcript of Practicas Con MC68HC908QY4
![Page 1: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/1.jpg)
Practicas con MC68HC908QY4
Practica #1
Lectura de puerto A (interruptores) escritura en puerto B
Código del programa y esquemático
VSS16
PTB72
PTA0/AD0/TCH0/KBI013
PTA2/IRQ/KBI29
PTA3/RST/KBI38PTA4/OSC2/AD2/KBI4
5PTA5/OSC1/AD3/KBI5
4
VDD1
PTB310
PTB2 11
PTB114
PTB015
PTA1/AD1/TCH1/KBI112
PTB5 6
PTB47
PTB63
U1
MC68HC908QY4CP
VCC
GND
S?
SW-PB
S?
SW-PB
GND
GND
D?
LED0
D?
LED0D?
LED0
D?
LED0
D?
LED0
D?
LED0
D?
LED0
D?
LED0
GND
![Page 2: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/2.jpg)
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC68HC908QY4.h> /* include peripheral declarations */
#include <startup.h>
void inicializacion( void );
void main(void) {
inicializacion();
for(;;){ //ciclo infinito
if ( PTA_PTA0 == 0 ) { //DECLARAMOS CONDICION PARA EL PUERTO A
PTB= 0xFF;
}else{
PTB = 0x00;
}
}
}
void inicializacion(){
CONFIG1 = 0x09; // Deshabilita el perro guardián
OSCTRIM = 0x80; // Registro de ajuste de oscilador interno
PTAPUE = 0x3F; // Resistencias de pull-up
DDRA = 0x00; // Puerto A, entradas.
DDRB = 0xFF; // Puerto B, salidas.
}
/* please make sure that you never leave this function */
![Page 3: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/3.jpg)
Practica 2
Contador de pulsos y salida en binario
El mismo esquematico
Programa
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
unsigned char val=0;
void inicializacion( void );
void retardo( unsigned int );
void main(void) {
inicializacion();
for(;;){
if (PTA_PTA0 == 0){
retardo(20000);
val=val+1;
}
PTB=val;
}
/* loop forever */
/* please make sure that you never leave this function */
}
![Page 4: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/4.jpg)
void inicializacion() {
CONFIG1 = 0x09; // Deshabilita el perro guardián
CONFIG2 = 0x00; //Configuramos no reset y cristal interno
OSCTRIM = 0x80; // Registro de ajuste de oscilador interno
PTAPUE = 0x3F; // Resistencias de pull-up
DDRA = 0x10; // Puerto A, entradas.
DDRB = 0xFF; // Puerto B, salidas.
}
void retardo( unsigned int ciclos ) {
unsigned int cuenta;
for ( cuenta = 0; cuenta < ciclos; cuenta++ );
}
![Page 5: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/5.jpg)
Practica 3
Desplazamiento de leds a la izquierda y a la derecha
Mismo esquematico
Programa
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
/////variables////////
const unsigned char leds[] = {
0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};
///////funciones//////
void inicializacion(void);
void retardo( unsigned int );
void secIzquierda( void );
void secDerecha( void );
////////programa principal////////////
void main(void) {
inicializacion();
for(;;){
if ( PTA_PTA0 == 0 )
secDerecha();
else if ( PTA_PTA1 == 0 )
secIzquierda();
![Page 6: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/6.jpg)
else
PTB = leds[ 0 ]; // PTB = 0x00;
}
/* please make sure that you never leave this function */
}
void inicializacion() {
CONFIG1 = 0x09; // Deshabilita el perro guardián
CONFIG2 = 0x00;
OSCTRIM = 0x80; // Registro de ajuste de oscilador interno
PTAPUE = 0x3F; // Resistencias de pull-up
DDRA = 0x00; // Puerto A, entradas.
DDRB = 0xFF; // Puerto B, salidas.
}
void retardo( unsigned int ciclos ) {
unsigned int cuenta;
for ( cuenta = 0; cuenta < ciclos; cuenta++ );
}
void secDerecha() {
int cuenta;
for ( cuenta = 0; cuenta < 9; cuenta++ ) {
PTB = leds[ cuenta ];
retardo( 20000 );
}
}
![Page 7: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/7.jpg)
void secIzquierda() {
int cuenta;
for ( cuenta = 8; cuenta >= 0; cuenta-- ) {
PTB = leds[ cuenta ];
retardo( 20000 );
}
}
![Page 8: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/8.jpg)
Practica 4
Tarjeta de visualizador de display 7 segmentos
VSS16
PTB72
PTA0/AD0/TCH0/KBI013
PTA2/IRQ/KBI29
PTA3/RST/KBI38
PTA4/OSC2/AD2/KBI45 PTA5/OSC1/AD3/KBI54
VDD1
PTB310
PTB211
PTB114
PTB015
PTA1/AD1/TCH1/KBI112
PTB56
PTB47
PTB63
U1
MC68HC908QY4CP
VCC
GND
S?
SW-PB
S?
SW-PB
GND
GND
D?
LED0
D?
LED0D?
LED0
D?
LED0
D?
LED0
D?
LED0
D?
LED0
D?
LED0
GND
K1
f2
g3
e4
d5
K6
c8
DP7
b9
a10
DS?
Dpy Amber-CC
GND
![Page 9: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/9.jpg)
Programa
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
unsigned char val=0;
void inicializacion(void);
void retardo( unsigned int );
char segmentos( unsigned char );
void main(void) {
inicializacion();
/* include your code here */
for(;;){
if(PTA_PTA0 == 0){
retardo(24000);
val=val+1;
}
if ( PTA_PTA1 == 0 ){
retardo(24000);
val=val-1;
}
PTB=segmentos(val);
}
/* loop forever */
/* please make sure that you never leave this function */
![Page 10: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/10.jpg)
}
void inicializacion(){
CONFIG1=0x09;
CONFIG2=0x00;
OSCTRIM=0x80;
PTAPUE=0x3F;
DDRA = 0x00; // Puerto A ENTRADAS
DDRB = 0xFF; // Puerto B salidas
}
void retardo( unsigned int ciclos ) {
unsigned int cuenta;
for ( cuenta = 0; cuenta < ciclos; cuenta++ );
}
char segmentos(unsigned char val){
unsigned char valseg;
switch (val){
case 0:
valseg=0x3F;
break;
case 1:
valseg=0x06;
break;
case 2:
![Page 11: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/11.jpg)
valseg=0x5B;
break;
case 3:
valseg=0x4F;
break;
case 4:
valseg=0x66;
break;
case 5:
valseg=0x6D;
break;
case 6:
valseg=0x7D;
break;
case 7:
valseg=0x07;
break;
case 8:
valseg=0x7F;
break;
![Page 12: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/12.jpg)
case 9:
valseg=0x6F;
break;
}
return valseg;
}
![Page 13: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/13.jpg)
Practica 5 y 6
Control de relevador de CA para energizar bomba y para control de triac
Esquemático para triac
Q?Triac
1K
R?
Res2
U?
Opto TRIAC
DS?
Lamp
1K
R?
Res2
GND
CA
K?
Relay-DPST
K10
IN6 6
OUT712
IN77
OUT613OUT514
IN33
OUT415
IN1 1
OUT316 IN2
2
OUT811
GND 9
IN44
IN88
IN5 5
OUT118
OUT217
U2
ULN2803AGND
D?D Zener
GND
VCC
VCC
![Page 14: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/14.jpg)
Esquema para relevador
VSS16
PTB7 2
PTA0/AD0/TCH0/KBI013
PTA2/IRQ/KBI29 PTA3/RST/KBI38 PTA4/OSC2/AD2/KBI45 PTA5/OSC1/AD3/KBI54
VDD 1
PTB3 10
PTB2 11
PTB1 14
PTB0 15
PTA1/AD1/TCH1/KBI112
PTB5 6
PTB4 7
PTB6 3
U1
MC68HC908QY4CP
VCC
GND
S?
SW-PB
S?
SW-PB
ULN2803AD?D Zener
GND1K
R?RPot
GND
VCC
Programa, aquí se utilizo el ADC del micro para activar una salida a partir de que rebasa los 2.5 volts en el AN3, pin 4
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
byte result;
![Page 15: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/15.jpg)
void inicializacion(void);
void main(void) {
inicializacion();
for(;;){
ADSCR = 0x23;
result = ADR;
PTB=result;
if(result>0x7F){
PTA_PTA0=1;
}else{
PTA_PTA0=0;
}
}
/* loop forever */
/* please make sure that you never leave this function */
}
![Page 16: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/16.jpg)
void inicializacion(){
CONFIG1=0x09;
OSCTRIM=0x80;
DDRA = 0x1B;
DDRB = 0xFF;
ADICLK = 0x40;
ADSCR = 0x23;
}
![Page 17: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/17.jpg)
Practica 7
Manejo de un teclado numérico y mostrar la tecla en un display 7 segmentos
Esquematico
VSS 16
PTB72
PTA0/AD0/TCH0/KBI0 13
PTA2/IRQ/KBI29PTA3/RST/KBI38PTA4/OSC2/AD2/KBI45
PTA5/OSC1/AD3/KBI5 4
VDD1
PTB310
PTB211
PTB114
PTB015
PTA1/AD1/TCH1/KBI112
PTB56
PTB47
PTB63
U?
MC68HC908QY4CP
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
S?
SW-PB
f9g10
e1
d2
K3
c 4
DP 5
b 6
a 7K8
DS?
Dpy Blue-CC
![Page 18: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/18.jpg)
Código de programa
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
void inicializacion(void);
void retardo( unsigned int );
void main(void) {
inicializacion();
EnableInterrupts; /* enable interrupts */
/* include your code here */
PTB=0x00;
for(;;) {
PTA_PTA0=1;
if((PTA_PTA3==1)&&(PTA_PTA0==1)){
![Page 19: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/19.jpg)
PTB=0x06;
retardo(24000);
}
if((PTA_PTA4==1)&&(PTA_PTA0==1)){
PTB=0x5B;
retardo(24000);
}
if((PTA_PTA5==1)&&(PTA_PTA0==1)){
PTB=0x4F;
retardo(24000);
}
PTA_PTA0=0;
PTA_PTA1=1;
if((PTA_PTA3==1)&&(PTA_PTA1==1)){
PTB=0x66;
retardo(24000);
}
if((PTA_PTA4==1)&&(PTA_PTA1==1)){
PTB=0x6D;
retardo(24000);
}
if((PTA_PTA5==1)&&(PTA_PTA1==1)){
PTB=0x7D;
retardo(24000);
![Page 20: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/20.jpg)
}
PTA_PTA1=0;
PTA_PTA2=1;
if((PTA_PTA3==1)&&(PTA_PTA2==1)){
PTB=0x07;
retardo(24000);
}
if((PTA_PTA4==1)&&(PTA_PTA2==1)){
PTB=0x7F;
retardo(24000);
}
if((PTA_PTA5==1)&&(PTA_PTA2==1)){
PTB=0x67;
retardo(24000);
}
PTA_PTA2=0;
__RESET_WATCHDOG(); /* feeds the dog */
![Page 21: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/21.jpg)
} /* loop forever */
/* please make sure that you never leave main */
}
void inicializacion(){
CONFIG1=0x09;
OSCTRIM=0x80;
DDRA = 0x07;
DDRB = 0xFF;
}
void retardo( unsigned int ciclos ) {
unsigned int cuenta;
for ( cuenta = 0; cuenta < ciclos; cuenta++ );
}
![Page 22: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/22.jpg)
Practica 8
Control de Motor PP velocidad y direccion
Esquematico, el que vemos anteriormente, con el uln2803 y las salidas al motor PP , la dirección la controlas por los dipswitch de a0 y a1, y la velocidad mediante el potenciómetro, dependiendo del valor analógico mayor es la velocidad
VSS16
PTB72
PTA0/AD0/TCH0/KBI013
PTA2/IRQ/KBI29
PTA3/RST/KBI38
PTA4/OSC2/AD2/KBI45
PTA5/OSC1/AD3/KBI54
VDD1
PTB3 10
PTB211
PTB114
PTB015
PTA1/AD1/TCH1/KBI112
PTB56
PTB47
PTB63
U?
MC68HC908QY4CP
IN11
IN22
IN33
IN44
IN55
IN66
IN77
IN88
OUT118
OUT316
OUT415
OUT514
OUT6 13
OUT712
OUT811
OUT217
COM D10
GND9
U?
ULN2803AGND
GND
VCC
D?D Zener
VCC
12345
P?
Header 5
VCC
1K
R?RPot
GND
VCC
S?
SW-PBS?
SW-PB
GND
Programa
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
![Page 23: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/23.jpg)
const unsigned char leds[] = {
0x01, 0x02, 0x04, 0x08
};
unsigned int valor;
void inicializacion(void);
void retardo (unsigned int);
void secIzquierda( void );
void secDerecha( void );
void main(void) {
inicializacion();
for(;;) {
![Page 24: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/24.jpg)
ADSCR = 0x23;
valor = ADR;
valor = valor*200;
if(PTA_PTA0 == 0)
secDerecha();
else if (PTA_PTA1 == 0)
secIzquierda();
else
PTB = 0x00; // PTB = 0x00;
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
![Page 25: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/25.jpg)
void inicializacion(){
CONFIG1= 0x09;
OSCTRIM = 0x80;
PTAPUE = 0x1F; // Resistencias de pull-up
DDRA = 0x00; // Puerto A, entradas.
DDRB = 0xFF; // Puerto B, salidas.
ADICLK = 0x40; // Divisor de velocidad del bus entre 4 para
// que el ADC trabaje a 3.2 MHz / 4 < 1 MHz.
// Conversiones continuas, interrupciones
}
void retardo( unsigned int ciclos ) {
unsigned int cuenta;
for ( cuenta = 0; cuenta < ciclos; cuenta++ );
}
void secDerecha() {
![Page 26: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/26.jpg)
int cuenta;
for ( cuenta = 0; cuenta < 4; cuenta++ ) {
PTB = leds[ cuenta ];
retardo( valor );
}
}
void secIzquierda() {
int cuenta;
for ( cuenta = 3; cuenta >= 0; cuenta-- ) {
PTB = leds[ cuenta ];
retardo( valor );
}
}
![Page 27: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/27.jpg)
Practica 9
Medición de velocidad de un motor de CD para formar grafica
VSS16
PTB7 2
PTA0/AD0/TCH0/KBI013
PTA2/IRQ/KBI29
PTA3/RST/KBI38PTA4/OSC2/AD2/KBI4
5PTA5/OSC1/AD3/KBI54
VDD1
PTB310
PTB211
PTB114
PTB0 15
PTA1/AD1/TCH1/KBI112
PTB5 6
PTB47
PTB63
U?
MC68HC908QY4CP
C1+1
VDD2
C1-3
C2+4
C2-5
VEE 6
T2OUT7
R2IN 8R2OUT9
T2IN10 T1IN11
R1OUT12
R1IN13
T1OUT14
GND15
VCC16
U?
MAX232ACPE
1
2
3
4
5
6
7
8
9
11
10
J?
D Connector 9
VCC
VCC
GND
GND
S?
SW-PB
GND
GND
10uF
C?
Cap Pol1
10uF
C?
Cap Pol1
GND
VCC
12
Y?XTAL1M
Programa, lo que va a hacer, es mediante la interrupción externa, nosotros vamos a poder contar los pulsos que nos va a indicar un optointerruptor, y cada segundo, se va a desplegar la velocidad en la computadora mediante la hyperterminal
Código
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <startup.h>
![Page 28: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/28.jpg)
unsigned char flag=0;
interrupt 2 void cargar_dato_serie(void);
interrupt 6 void TIMER();
void delay_baudio(void);
unsigned char tiempo_bit;
void inicializacion(void);
void Configurar_Timer(void);
void Transmitir_Caracter(void);
unsigned char Caracter =0;
unsigned char bit;
void main(void) {
inicializacion();
Configurar_Timer();
EnableInterrupts;
![Page 29: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/29.jpg)
PTB=0x00;
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
void inicializacion() {
CONFIG1 = 0x09; // Deshabilita el perro guardián
// Registro de ajuste de oscilador interno
DDRA = 0x38; // Pines 5,4 y 3 salidas, 0 y 2 entradas.
DDRB = 0xff; // Puerto B salidas
![Page 30: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/30.jpg)
CONFIG2 = 0x58; // Resistencia de pull-up habilitada para el pin A2 que
// funciona como IRQ.
INTSCR = 0x00; // Habilita interrupción por IRQ.
}
//////////CONFIGURACION TIMER REGISTROS////////////
void Configurar_Timer(void){
TSC = 0X70; /*Stop & reset,interrupcion activa, prescaler= 0*/
TSC0 = 0; /*Resto de funciones desactivadas*/
TSC1 = 0;
TMODH = 0xFF; /* Se carga el módulo con 04E4 (1252 decimal)*/
TMODL = 0xFF;
TSC ^= 0x10; /*Un-reset TIMer*/
}
///////////interrupcion externa////////////////
![Page 31: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/31.jpg)
interrupt 2 void cargar_dato_serie( void ) {
flag++;
// Borra la bandera del IRQF1
INTSCR_ACK = 1;
}
////////////INTERRUPCION TIMER///////////////
interrupt 6 void TIMER(){
Caracter=flag;
Transmitir_Caracter();
flag=0;
TSC ^= 0x80; /* Se borra la bandera de la interrupción */
}
/*******************************************************/
![Page 32: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/32.jpg)
/* Subrutina que maneja el Tranmisor */
/*******************************************************/
void Transmitir_Caracter(void){
//DisableInterrupts; /*Interrupciones Desactivadas*/
__RESET_WATCHDOG();
bit =0;
PTB_PTB0 = 0; //Pongo el bit de inicio
delay_baudio();
do{
if(Caracter & 0x01 == 0x01){
PTB_PTB0 = 1; //Pongo TX en 1
delay_baudio();
}
else
{
PTB_PTB0 = 0; //Pongo TX en 0
delay_baudio();
}
Caracter = Caracter >>1; //Roto para pasar los 8 bits
bit++;
}while(bit <=7);
PTB_PTB0 = 1; //Pongo el bit de Stop
delay_baudio();
__RESET_WATCHDOG();
}
![Page 33: Practicas Con MC68HC908QY4](https://reader034.fdocuments.net/reader034/viewer/2022052321/55216226497959734d8b4906/html5/thumbnails/33.jpg)
void delay_baudio(void){
for(tiempo_bit=0;tiempo_bit <=10;tiempo_bit++){
}
}