+/File Name: DDrt
//Purpose: write programs in C
//Programmer: Carlos De La Cruz,Terky
//Date:3/30/2017
Exercise 1
DDRT &= 0x00;
PPST &= 0xF0;
PERT |=0xF0;
DDRH =0x00;
PTT= PTH ;
Lab exercise 1
#include "derivative.h" /* derivative-specific definitions */
// Display PA on 7-seg Display #include "hcs12.h" /* common defines and macros */
void SetClk8(void); /* available from Chapter 06 */
void delayby1ms(int); /* available from Chapter 05 */
void main(void) { /* put your own code here */
SetClk8();
DDRJ |= 0x02;
PTJ |= 0x02; // disable LEDs
DDRP |= 0x0f;
DDRB = 0xff;
while (1) {
PTP = 0xfd;
PORTB = 0x79; // display e
delayby1ms(2);
PTP = 0xfb;
PORTB = 0x38; // display l
delayby1ms(2);
PTP = 0xf7;
PORTB = 0x73;
delayby1ms(2);
PTP = 0xfe;
PORTB = 0x76; // display A
delayby1ms(2);
} /* please make sure that you never leave main */ } ]
\
// Example 1a: Turn on every other segment on 7-seg display
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include "main_asm.h" /* interface to the assembly module */
void main(void) {
/* put your own code here */
PLL_init(); // set system clock frequency to 24 MHz
seg7_enable(); // disable 7-segment displays
led_disable(); // enable LEDs
DDRH = 0x00; // Port H inputs
while(1) {
leds_on(~PTH);
}
Lab exercise 3
// Example 1a: Turn on every other segment on 7-seg display
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include "main_asm.h" /* interface to the assembly module */
void delay(void);
void main(void) {
PLL_init(); // set system clock frequency to 24 MHz
seg7_disable(); // disable 7-segment displays
led_enable(); // enable LEDs
DDRH = 0x00; // Port H inputs
while(1) {
if(PTH!=0xff) { //all dip switches off
leds_on(0x80);//lights up led7
delay();
leds_on(0x20);//lights up led5
delay();
}
else{ //dip switch is down
leds_on(0x01); //lights up led0
delay(); //delay needed in between each led
leds_on(0x04); //lights up led2
delay();
void delay() {
int i,j;
for(i = 0; i < 500; i++) {
for(j = 0; j < 6248; j++) {}
}
}
Lab exercise 4
Step 1
There Are 4 inputs and 4 outputs
Step 2
The 7 segment display can only show four numbers 2 ms for each number that’s 8 ms which generate a
frequency of 125 hz and loop 600/8 =75 which is the number of times you loop the pattern so the delay
can be 600 ms .
Step 3
// Example 1a: Turn on every other segment on 7-seg display
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include "main_asm.h" /* interface to the assembly module */
int i;
void main(void) {
/* put your own code here */
PLL_init(); // set system clock frequency to 24 MHz
DDRB = 0xff; // Port B is output
DDRJ = 0xff; // Port J is output
DDRP = 0xFF; // Port P is output
PTJ = 0x02; // enable LED
PTP = 0x00; // enable all 7-segment displays
// turn on every other led and segment on 7-seg displays
while(1){
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x06;
ms_delay(2);
PTP=0x0d;
PORTB=0x5b;
ms_delay(2);
PTP=0x0b;
PORTB=0x4f;
ms_delay(2);
PTP=0x07;
PORTB=0x66;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x5b;
ms_delay(2);
PTP=0x0d;
PORTB=0x4f;
ms_delay(2);
PTP=0x0b;
PORTB=0x66;
ms_delay(2);
PTP=0x07;
PORTB=0x6d;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x4f;
ms_delay(2);
PTP=0x0d;
PORTB=0x66;
ms_delay(2);
PTP=0x0b;
PORTB=0x6d;
ms_delay(2);
PTP=0x07;
PORTB=0x7d;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x66;
ms_delay(2);
PTP=0x0d;
PORTB=0x6d;
ms_delay(2);
PTP=0x0b;
PORTB=0x7d;
ms_delay(2);
PTP=0x07;
PORTB=0x07;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x6d;
ms_delay(2);
PTP=0x0d;
PORTB=0x7d;
ms_delay(2);
PTP=0x0b;
PORTB=0x07;
ms_delay(2);
PTP=0x07;
PORTB=0x7f;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x7d;
ms_delay(2);
PTP=0x0d;
PORTB=0x07;
ms_delay(2);
PTP=0x0b;
PORTB=0x7f;
ms_delay(2);
PTP=0x07;
PORTB=0x6f;
ms_delay(2);
}
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x07;
ms_delay(2);
PTP=0x0d;
PORTB=0x7f;
ms_delay(2);
PTP=0x0b;
PORTB=0x6f;
ms_delay(2);
PTP=0x07;
PORTB=0x3f;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x7f;
ms_delay(2);
PTP=0x0d;
PORTB=0x6f;
ms_delay(2);
PTP=0x0b;
PORTB=0x3f;
ms_delay(2);
PTP=0x07;
PORTB=0x06;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x6f;
ms_delay(2);
PTP=0x0d;
PORTB=0x3f;
ms_delay(2);
PTP=0x0b;
PORTB=0x06;
ms_delay(2);
PTP=0x07;
PORTB=0x5b;
ms_delay(2);
for( i=0;i<75;i++){
PTP=0x0E;
PORTB=0x3f;
ms_delay(2);
PTP=0x0d;
PORTB=0x06;
ms_delay(2);
PTP=0x0b;
PORTB=0x5b;
ms_delay(2);
PTP=0x07;
PORTB=0x4f;
ms_delay(2);
}
}
Step 4