93 lines
3.9 KiB
C
93 lines
3.9 KiB
C
//////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// ADC Sample for SofTec Microsystems' IDB-HC08JK Demo Board
|
|
//
|
|
// This program configures the A/D peripheral to convert on A/D channel 9
|
|
// (PTD2, connected to the potentiometer) and displays the results on the LEDs
|
|
// on PTB[7..4] and PTD[7..4]. Make sure that all of the "LED ENABLE" jumpers
|
|
// and the "POTENTIOMETER ENABLE" jumper are inserted.
|
|
// ---------------------------------------------------------------------------
|
|
// Copyright (c) 2002 SofTec Microsystems
|
|
// http://www.softecmicro.com/
|
|
//
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
#include "hidef.h"
|
|
#include "derivative.h"
|
|
|
|
#pragma DATA_SEG SHORT _DATA_ZEROPAGE
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Defines
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
#define Switch PTB_PTB5
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Registers definition
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//volatile unsigned char PTB @0x0001; // Port B data register
|
|
//volatile unsigned char PTD @0x0003; // Port D data register
|
|
//volatile unsigned char DDRB @0x0005; // Port B data direction register
|
|
//volatile unsigned char DDRD @0x0007; // Port D data direction register
|
|
//volatile unsigned char CONFIG1 @0x001F; // Configuration register 1
|
|
//volatile unsigned char ADSCR @0x003C; // ADC status and control register
|
|
//volatile unsigned char ADR @0x003D; // ADC data register
|
|
//volatile unsigned char ADICLK @0x003E; // ADC input clock register
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Variables
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
unsigned char tmp;
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Interrupt Routines
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
interrupt VectorNumber_ADC void IntADC(){
|
|
tmp = 0;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Entry Point
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
void main (void) {
|
|
EnableInterrupts; // Enables Global Interrupt
|
|
CONFIG1 |= 0x01; // Disables COP
|
|
DDRB = 0xF0; // Configures port B[7..4] as output
|
|
DDRD = 0xF0; // Configures port D[7..4] as output
|
|
ADSCR = 0x29; // Enables ADC channel 9
|
|
ADICLK = 0x40; // ADC input clock / 4
|
|
|
|
for(;;) // Forever
|
|
{
|
|
while(!(ADSCR & 0x80)) // Waits for ADC end of conversion
|
|
;
|
|
tmp = ADR; // Saves the ADC value on a temporary data
|
|
PTD = tmp; // Writes the ADC value on port D[7..4]
|
|
PTB = tmp << 4; // Writes the ADC value on port B[7..4]
|
|
if(!Switch){
|
|
PTD = 0xF0;
|
|
PTB = 0xF0;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// IRQ Interrupt Handler
|
|
// ---------------------
|
|
// This subroutine is needed to implement the "Halt" debugging command.
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
void irq_isr (void)
|
|
{
|
|
asm {
|
|
wait_irq:
|
|
bil wait_irq // Waits for the IRQ signal to go high
|
|
swi // Jumps to monitor code
|
|
rti
|
|
};
|
|
}
|