- MAX+PlusII Code (Altera FPGA)
--Synchronous
State Machine
--Makes use of the STD system clock of 4Mhz
--Variables used
--int
- interrupt from switch
--iack -interrrupt acknowledge from processor
SUBDESIGN
intsm18a
(
inpulse, /reset, int,PCI,/INTAK :INPUT;
/irq :OUTPUT;
)
VARIABLE
--define
INPUT variables with active low signals
reset,INTAK :NODE;
--define state
machine
sm: MACHINE WITH STATES (s0,s1,s2,s3);
BEGIN
--equations for
INPUT variables with active low signals
reset = !/reset;
INTAK=!/INTAK;
--equations
for state machine clock
sm.clk = inpulse;
sm.reset = reset;
--description
of state machine
CASE sm IS
WHEN s0=>
/irq = VCC;
IF int
THEN sm = s1;
ELSE sm = s0;
END IF;
WHEN s1=>
/irq = GND;
IF (PCI & INTAK) THEN sm = s2;
ELSE sm = s1;
END IF;
WHEN s2=>
/irq = GND;
IF INTAK THEN sm=s2;
ELSE sm=s3;
END IF;
WHEN s3
=>
/irq = VCC;
IF int THEN sm=s3;
ELSE sm=s0;
END IF;
END
CASE;
END;
Go To Top
- C++ Linked List Example
//Implementor
for linklist.hpp
#include "luclist.hpp"
#include
#include
#include
listClass::listClass():Head(NULL)
{
}
int
listClass::ListSize(ptrType& Head)
{
int counter = 0;
ptrType
Tail = Head; //Tail points to beggining of list
if (Tail->Next != NULL)
do
{
Tail = Tail->Next;
counter++;
}
while (Tail->Next
!= NULL);
return(counter);
}
void listClass::Addtofront (int counter,ptrType&
Head)
{
ptrType NewPointer;
NewPointer = new node;
NewPointer->Next
= Head; //NewPointer now points to Pointer
Head = NewPointer; //Head now
points to NewPointer
NewPointer->Item = counter;
}
void listClass::Addtoend(int
counter, ptrType& Head)
{
ptrType Current = new node;
ptrType Tail
= Head; //Tail points to beggining of list
while (Tail->Next != NULL)
{
Tail = Tail->Next;
//This get's Tail to last element
}
Tail->Next = Current;
Current->Item = counter;
Current->Next = NULL;
}
void
listClass::Deletefront(ptrType& Head)
{
ptrType Current;
Current = Head;
Head
= Current->Next;
delete Current;
Current = NULL;
}
void listClass::PrintList(ptrType
Head)
{
ptrType Current;
Current = Head; //copies head into current
if(Current != NULL) //from p185
{
cout << "Current->Item =
" << Current->Item < PrintList(Current->Next);
return;
}
getchar();
}
Go To Top
- Microchip 16F84 DAQ With
RS-232 Interface
include
;********************************************************************************
;*Programmer-Lucius
Perreault *
;*06/05/00 *
;*Description: *
;*This program will read data
in from an a/d converter serially and then convert *
;*the information into a
4-bit BCD code. The code will then be transmitted *
;*serially at a 4600 baud
rate to an output. *
;********************************************************************************
;-------------------------------------------------------------------------------
;Registers
Data_Reg
equ H'20'
counter1 equ H'21'
TRANSMIT equ H'22' ;DATA to be transmitted serially
TRANSCOUNT
equ H'23' ;# of bits to be transmitted
BAUDCOUNT equ H'24' ;used for my baud rate
delay
H_Byte equ H'25' ;Hi byte of my input data
L_Byte equ H'26' ;Lo byte
of my input data
temp equ H'27'
R2 equ H'28' ;LSB of my BCD code
R1 equ
H'29' ;CSB of my BCD code
R0 equ H'30' ;MSB of my BCD code
count equ H'31'
;-------------------------------------------------------------------------------
;Constants
constant RA0=D'0' ;Data in from A/D
constant RA1=D'1' ;400kHz clock out
constant
RA2=D'2' ;Power Swich
constant RA3=D'3' ;Gain Control
constant RA4=D'4'
constant RB0=D'0'
constant RB1=D'1' ;!Chip Select of A/D
constant RB2=D'2'
constant RB3=D'3'
constant RB4=D'4'
constant RB5=D'5'
constant RB6=D'6'
;transmit data to RS-232 @4800 baud rate
constant RB7=D'7'
;-------------------------------------------------------------------------------
Start
call Initalize_Ports
Temporary
bsf PORTB,RB1 ;Unselect the A/D chip
call
Get_Data_ADC ;get my data
movf Data_Reg,W ;W must contain data to transmit before
I call Start_Data
movwf L_Byte
call B2_BCD
movf R1,W
call Start_Data
movf R0,W
call Start_Data
movlw H'0D'
call Start_Data
goto Temporary
;-------------------------------------------------------------------------------
Initalize_Ports
clrf PORTA ;clear contents of PORTA
bsf STATUS,RP0 ;select bank 1
movlw 0x01
;Set up porta
;RA0 = data receive(input)
;RA1 = clock out (output)
;RA2
= Power Switch (output)
;RA3 = Gain Control (output)
movwf TRISA
bcf
TRISB,RB1 ;!Chipselect of A/D
bcf TRISB,RB6 ;data out for RS-232 transmission
bcf STATUS,RP0 ;bank 0
return
;-------------------------------------------------------------------------------
;Note:
CHIPSELECT->(CLOCKPULSE->READBIT)*8
Get_Data_ADC
;btfsc PORTA,0 ;wait
until you get a start bit
;goto Get_Data_ADC
movlw 8 ;there are 8 bits to
be read in
movwf counter1
bcf PORTB,RB1 ;assert !ChipSelect pin
Get_Next_Bit
Clock_Pulse
bsf PORTA,RA1 ;pgt
nop ;duty cycle
bcf PORTA,RA1 ;ngt
btfss
PORTA,RA0
bcf Data_Reg,7
btfsc PORTA,RA0
bsf Data_Reg,7
rlf Data_Reg
decfsz counter1
goto Get_Next_Bit
bsf PORTB,RB1 ;don't need Chip Selected
anymore
return
;-------------------------------------------------------------------------------
Clock_Pulse_version1
;This
Subroutine will Pulse RA0 which is connected to my clock input on the AD
;It will
include my settling time for data on the NGT
bsf PORTA,RA1
nop
bcf PORTA,RA1
return
;-------------------------------------------------------------------------------
Delay_5us
;1uS
instruction = 1Mhz operating time = 4Mhz/4
;I will clock at 400kHZ\
;3nops(1us)+1return(2us)
= 5us
;1/5uS = 200kHz *2(hi/lo) = 400khz clock
nop
nop
nop
return
;-------------------------------------------------------------------------------
;Send
out data to PORTC bit 6 MSB First (NEW)
Baud_Delay
;1/4800 = 208.3 uS
;I
used 4800 baud rate because that is what were gonna need for
;Johns serial transmission
as well(thinking ahead!!!).
movlw D'40' ;52,37
movwf BAUDCOUNT ;
Baud_Decrement
nop
nop
decfsz BAUDCOUNT
goto Baud_Decrement
return
Start_Data
movwf TRANSMIT ;W contains the data to be transmitted already
movlw H'09'
movwf TRANSCOUNT
bcf PORTB,6 ;low for start bit
Transmit_Data
call
Baud_Delay
rrf TRANSMIT ;Transmit contains character to go out serial
btfsc
STATUS,C
bsf PORTB,6
btfss STATUS,C
bcf PORTB,6
decfsz TRANSCOUNT
goto Transmit_Data
Stop_Data
call Baud_Delay ;used because I Delay at
the beginning of Transmit_Data
bsf PORTB,6 ;changed from porta,6 to portb,6
call Baud_Delay ;Hold DX hi for a 1/baud
End_Transmit
return
;-------------------------------------------------------------------------------
B2_BCD
bcf STATUS,C ;Clear the carry bit
movlw .16
movwf count
clrf R0
clrf
R1
clrf R2
Loop16
rlf L_Byte,F
rlf H_Byte,F
rlf R2,F
rlf R1,F
rlf R0,F
decfsz count,F
goto adjDEC
RETLW 0
adjDEC
movlw R2
movwf FSR
call adjBCD
movlw R1
movwf FSR
call
adjBCD
movlw R0
movwf FSR
call adjBCD
goto Loop16
adjBCD
movlw 3
addwf 0,W
movwf temp
btfsc temp,3 ;test if result >7
movwf
0
movlw H'30'
addwf 0,W
movwf temp
btfsc temp,7
movwf 0
RETLW
0
end
Go To Top