Assembly Programming an LCD and AVR

Discussion in 'Embedded Systems and Microcontrollers' started by Colossus, Aug 23, 2009.

  1. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    The following assembly code is for a Mini DDS that generates sine, sawtooth, triangle and square waves. Frequency range is from 0.07 Hz up to 200 kHz or more. It allows you to control the frequency with 2 push buttons( up increases frequency by 10 and down decreases by 1).

    I am attempting to add an LCD HD44780 to display the frequency but my assembly programming skills are pretty bad. I was wondering if someone could help me with the code?

    Here is a link to the schematic.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. ;*******************************************************************
    4. ;*******************************************************************
    5. ;
    6. ;Description
    7. ;
    8. ; Poor-mans DDS Synthesizer
    9. ;
    10. ; Author = Jesper Hansen
    11. ; Target = AT90S2313
    12. ; Date   = 2001-02-15
    13. ;
    14. ;
    15. ; Extensively modified by Leon Heller
    16. ;
    17. ; 4/10/02   Modified for the Atmel AVR assembler
    18. ; 18/08/02    Modified for the ATtiny2313
    19. ; 18/08/02    RS-232 stuff removed
    20. ; 19/08/06    Timer0 interrupt used for timing
    21. ; 21/08/06   Pushbuttons for frequency up/down added
    22. ;
    23. ; PB0..7 = D/A Data out
    24. ; PD2 (pin 6) SW1 input
    25. ; PD3 (pin 7) SW2 input
    26. ; PD0 (pin 2) LED output
    27. ;
    28. ;*******************************************************************
    29. ;*******************************************************************
    30. ;
    31. ;
    32. ;
    33. ; Output frequency (using 24 bit accumulator) :
    34. ;
    35. ;   f = deltaPhase * fClock/2^24
    36. ;
    37. ;   fClock is in this case the CPU clock divided by the
    38. ;   number of cycles to output the data ( 9 cycles )
    39. ;
    40. ;   f = r24/r25/r26 * (11059200/9)/16777216
    41. ;
    42. ;   f = r24/r25/r26 * 0.073242188
    43. ;
    44. ;   fMax (theoretical) = 0.5 * fClock
    45. ;
    46.  
    47.  
    48. #define Temp r16
    49. #define Flags r18
    50. #define Delay_count 0xFF
    51. #define sw1 0  
    52.  
    53. ;******************************************************************************
    54. ; start of code
    55. ;******************************************************************************
    56.  
    57.    .nolist
    58.    .include "tn2313def.inc"
    59.    .list
    60.  
    61.    .cseg
    62.  
    63.    .org 0
    64.       rjmp   RESET
    65.    .org 0x0005
    66.       rjmp   TIMER1_OVF
    67.    .org 0x0006
    68.       rjmp   TIMER0_OVF
    69.  
    70.  
    71. ;******************************************************************************
    72. ; code
    73. ;******************************************************************************
    74.  
    75.  
    76. RESET:
    77.       ldi      Temp, RAMEND
    78.       out      SPL, Temp      ; setup stack pointer
    79.  
    80.       ser      Temp            ;
    81.       out      DDRB,Temp      ; set all PORTB bits as output
    82.       sbi      PORTD,PD2      ; pullup on PD2 input
    83.       sbi      PORTD,PD3      ; pullup on PD3 input
    84.       sbi      DDRD,PD0      ; PD0 output
    85.  
    86.  
    87.       ; set up Timer/Counter 0
    88.  
    89.       ldi    Temp,0x01
    90.       out    TCCR0,Temp       ; Timer clock = system clock (no prescale)
    91.       ldi    Temp,1<<TOV0
    92.       out    TIFR,Temp       ; Clear TOV0/ clear pending interrupts
    93.       ldi    Temp,1<<TOIE0
    94.       out    TIMSK,Temp       ; Enable Timer/Counter0 Overflow Interrupt
    95.       ldi      Temp,Delay_count
    96.       out      TCNT0,Temp
    97.       sei                  ; global enable interrupts
    98.          
    99.  
    100.       ; set sinewave output as default
    101.      
    102.       ldi      ZH,high(2*sine)   ; setup Z pointer hi
    103.       ldi      ZL,low(2*sine)   ; setup Z pointer lo
    104.  
    105.  
    106.       ; clear accumulator
    107.  
    108.       ldi    r29,0x00      ; clear accumulator
    109.       ldi    r28,0x00      ; clear accumulator
    110.  
    111.       ; setup adder registers      
    112.      
    113.       ldi    r24,0x00      ; setup adder value
    114.       ldi    r25,0x88      ; to 1 kHz
    115.       ldi    r26,0x08      ;
    116.      
    117.      
    118.      
    119.  
    120.  
    121.    
    122. loop1:
    123.       rcall   test_sw1
    124.       sbrs   Flags,sw1
    125.       rjmp   loop1
    126.       rcall   up
    127.       rjmp   loop1
    128.  
    129.  
    130.  
    131.    
    132. test_sw1:
    133.       sbic   PIND,PD2      ; SW1 pressed?
    134.       rjmp   test1         ; no, return with flag = 0
    135.       rcall   dly            ; debounce delay
    136.       sbic   PIND,PD2      ; SW1 still closed?
    137.       rjmp   test1         ; no, return with flag = 0
    138.       sbr      Flags,sw1      ; sw1 flag <- 1
    139.       rjmp   test2         ; return with dlaf <- 1
    140. test1:
    141.       cbr      Flags,sw1      ; sw1 flag <- 0
    142. test2:
    143.       ret
    144.  
    145.  
    146. up:
    147.       ldi      r16,10
    148.       add      r25,r16
    149.       ret
    150.  
    151. down:
    152.       ldi      r16,1  
    153.       sub      r25,r16
    154.      
    155.       ret
    156.  
    157. dly:
    158.       ret
    159.       ldi      r16,0x10
    160. dly1:
    161.       ldi      r17,0xFF
    162. dly2:
    163.       dec      r17
    164.       brne   dly2
    165.       dec      r16
    166.       brne   dly1
    167.       ret
    168.  
    169.  
    170. ; Timer0 overflow interrupt service routine
    171. ; r28,r29,r30 is the phase accumulator
    172. ; r24,r25,r26 is the adder value determining frequency
    173. ;
    174.  
    175. TIMER0_OVF:
    176.       add      r28,r24      ; add value to accumulator
    177.       adc      r29,r25  
    178.       adc      r30,r26
    179.       lpm               ; load byte from current table in ROM
    180.       out      PORTB,r0   ; output byte to port
    181.       ldi      Temp,Delay_count
    182.       out      TCNT0,Temp
    183.       reti
    184.  
    185.  
    186. TIMER1_OVF:
    187.  
    188.  
    189.       reti
    190.  
    191. ;******************************************************************************
    192. ; data tables
    193. ;******************************************************************************
    194.  
    195.    ; force table to begin at 256 byte boundary
    196.  
    197.    .org 0x200
    198.  
    199. sine:      ; 256 step sinewave table
    200.    .db   0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95,0x98,0x9c,0x9f,0xa2,0xa5,0xa8,0xab,0xae
    201.    .db   0xb0,0xb3,0xb6,0xb9,0xbc,0xbf,0xc1,0xc4,0xc7,0xc9,0xcc,0xce,0xd1,0xd3,0xd5,0xd8
    202.    .db   0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,0xed,0xef,0xf0,0xf2,0xf3,0xf5
    203.    .db   0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfc,0xfd,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff
    204.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfd,0xfc,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7
    205.    .db   0xf6,0xf5,0xf3,0xf2,0xf0,0xef,0xed,0xec,0xea,0xe8,0xe6,0xe4,0xe2,0xe0,0xde,0xdc
    206.    .db   0xda,0xd8,0xd5,0xd3,0xd1,0xce,0xcc,0xc9,0xc7,0xc4,0xc1,0xbf,0xbc,0xb9,0xb6,0xb3
    207.    .db   0xb0,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x98,0x95,0x92,0x8f,0x8c,0x89,0x86,0x83
    208.    .db   0x80,0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51
    209.    .db   0x4f,0x4c,0x49,0x46,0x43,0x40,0x3e,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27
    210.    .db   0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x13,0x12,0x10,0x0f,0x0d,0x0c,0x0a
    211.    .db   0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00
    212.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08
    213.    .db   0x09,0x0a,0x0c,0x0d,0x0f,0x10,0x12,0x13,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23
    214.    .db   0x25,0x27,0x2a,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c
    215.    .db   0x4f,0x51,0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c
    216.  
    217. square:      ; 256 step squarewave table
    218.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    219.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    220.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    221.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    222.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    223.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    224.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    225.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    226.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    227.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    228.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    229.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    230.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    231.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    232.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    233.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    234.  
    235.  
    236. ;******************************************************************************
    237. ; end of file  
    238. ;******************************************************************************
    239.  
    240.  
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Do you have any interest at all in programming?
     
  3. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    I am a senior majoring in computer science but i am not very good at assembly level programming. I did take RISC assembly language programming but my strengths are in high level programming.
     
  4. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    I made a diagram using the original PDF file, could you please let me know if the buttons and LCD are connected to the ATMEGA8 correctly?

    http://onfinite.com/libraries/1515060/741.jpg

    Here is the code i added to output the frequency to the LCD. AVR studio says there are a couple errors but let me know if i'm on the right track.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. ;*******************************************************************
    4. ;*******************************************************************
    5.  
    6. ; Output frequency (using 24 bit accumulator) :
    7. ;
    8. ;   f = deltaPhase * fClock/2^24
    9. ;
    10. ;   fClock is in this case the CPU clock divided by the
    11. ;   number of cycles to output the data ( 9 cycles )
    12. ;
    13. ;   f = r24/r25/r26 * (11059200/9)/16777216
    14. ;
    15. ;   f = r24/r25/r26 * 0.073242188
    16. ;
    17. ;   fMax (theoretical) = 0.5 * fClock
    18. ;
    19.  
    20.  
    21. #define Temp r16
    22. #define Flags r18
    23. #define Delay_count 0xFF
    24. #define sw1 0  
    25.  
    26. ;******************************************************************************
    27. ; start of code
    28. ;******************************************************************************
    29.  
    30.    .nolist
    31.    ;.include "tn2313def.inc"
    32.    .include "m32def.inc" ; ***
    33.    .list
    34.  
    35.    .equ lcden = 7 ; LCD Enable (Act as clk)
    36.    .equ lcdrs = 6 ; LCD register select
    37.    .equ lcdrw = 5 ; LCD read/write
    38.    .cseg
    39.  
    40.    .org 0
    41.       rjmp   RESET
    42.    .org 0x0005
    43.       rjmp   TIMER1_OVF
    44.    .org 0x0006
    45.       rjmp   TIMER0_OVF
    46.  
    47.  
    48. ;******************************************************************************
    49. ; code
    50. ;******************************************************************************
    51.  
    52. RESET:
    53.  
    54.  
    55.       ldi      Temp, RAMEND
    56.       out      SPL, Temp      ; setup stack pointer
    57.  
    58.       ser      Temp           ;
    59.       out      DDRB,Temp      ; set all PORTB bits as output
    60.       sbi      PORTD,PD2      ; pullup on PD2 input
    61.       sbi      PORTD,PD3      ; pullup on PD3 input
    62.       sbi      DDRD,PD0       ; PD0 output
    63.  
    64.  
    65.       ; set up Timer/Counter 0
    66.  
    67.       ldi    Temp,0x01
    68.       out    TCCR0,Temp       ; Timer clock = system clock (no prescale)
    69.       ldi    Temp,1<<TOV0
    70.       out    TIFR,Temp       ; Clear TOV0/ clear pending interrupts
    71.       ldi    Temp,1<<TOIE0
    72.       out    TIMSK,Temp       ; Enable Timer/Counter0 Overflow Interrupt
    73.       ldi    Temp,Delay_count
    74.       out    TCNT0,Temp
    75.       sei                  ; global enable interrupts
    76.          
    77.  
    78.       ; set sinewave output as default
    79.      
    80.       ldi      ZH,high(2*sine)   ; setup Z pointer hi
    81.       ldi      ZL,low(2*sine)   ; setup Z pointer lo
    82.  
    83.  
    84.       ; clear accumulator
    85.  
    86.       ldi    r29,0x00      ; clear accumulator
    87.       ldi    r28,0x00      ; clear accumulator
    88.  
    89.       ; setup adder registers      
    90.      
    91.       ldi    r24,0x00      ; setup adder value
    92.       ldi    r25,0x88      ; to 1 kHz
    93.       ldi    r26,0x08      ;
    94.      
    95.     ;*** LCD Reset ***
    96.      ldi r16, low (ramend) ;Stack setup
    97.      out spl, r16
    98.      ldi r16, high (ramend)
    99.      out sph, r16
    100.  
    101.      ser r16
    102.      out DDRD,r16        ; Setup port D as output for data
    103.     ldi r16, 0b11100000
    104.      out DDRC,r16        ; Setup port C for ctrl
    105.      rcall lcd_init      ; Call to LCD initialization
    106.      
    107.  
    108.  
    109. ; *** Output Freqencuy to LCD ***
    110. ;  run calculation every time the frequency changes,
    111. ;  and output the number to the LCD
    112. ;  f = r24/r25/r26 * 0.073242188
    113.  
    114. main:
    115.  
    116.  
    117.        ldi      r16,0x00     ; place cursor in 1st row, 1st char
    118.       rcall    lcd_cmd
    119.  
    120.       add      r28,r24      ; Calculate f
    121.       adc      r29,r25  
    122.       adc      r30,r26
    123.       lpm                   ; load byte from current table in ROM
    124.       out      PORTB,r0     ; output byte to port
    125.       ldi      Temp,Delay_count
    126.       out      TCNT0,Temp
    127.  
    128.       ldi      r16, TCNT0    ; load the freq value into regester
    129.       rcall    lcd_prt      ; display to screen
    130.       ret
    131.  
    132.  
    133. loop:
    134.  rjmp loop
    135.  
    136.  
    137. ;*** LCD initialization ***
    138. lcd_init:
    139.  ldi   r16,0x38       ;Function Set:8 bit mode & 5 x 7 dot font
    140.  rcall lcd_cmd
    141.  ldi   r16,0x38       ;Function Set:8 bit mode & 5 x 7 dot font
    142.  rcall lcd_cmd
    143.  ldi   r16,0x38       ;Function Set:8 bit mode & 5 x 7 dot font
    144.  rcall lcd_cmd
    145.  ldi   r16, 0x0F      ;Display on, cursor on, cursor blink
    146.  rcall lcd_cmd
    147.  ldi   r16, 0x06      ;auto increment cursor
    148.  rcall lcd_cmd
    149.  rcall main
    150.  ret
    151.  
    152.  
    153. ;*** Send data to be displayed ***
    154. lcd_prt:
    155.  cbi PORTC, lcdrs ; RS=1 sending instruction
    156.  nop
    157.  cbi PORTC, lcdrw ; RW=0 write operation
    158.  nop
    159.  out PORTD,r16    ; put data on bus
    160.  nop
    161.  sbi PORTC, lcden ; simulate +ve clk edge
    162.  nop
    163.  nop
    164.  nop
    165.  cbi PORTC, lcden ; simulate -ve clk edge
    166.  ret
    167.    
    168.  
    169. ;*** Send commmand to LCD ***
    170. lcd_cmd:
    171.  cbi PORTC, lcdrs ; RS=0 sending instruction
    172.  nop
    173.  cbi PORTC, lcdrw ; RW=0 write operation
    174.  nop
    175.  out PORTD,r16    ; put data on bus
    176.  nop
    177.  sbi PORTC, lcden ; simulate +ve clk edge
    178.  nop
    179.  nop
    180.  nop
    181.  cbi PORTC, lcden ; simulate -ve clk edge
    182.  ret
    183.  
    184.  
    185.  
    186. loop1:
    187.       rcall   test_sw1
    188.       sbrs   Flags,sw1
    189.       rjmp   loop1
    190.       rcall   up
    191.       rjmp   loop1
    192.  
    193.  
    194.  
    195.    
    196. test_sw1:
    197.       sbic   PIND,PD2      ; SW1 pressed?
    198.       rjmp   test1         ; no, return with flag = 0
    199.       rcall  dly           ; debounce delay
    200.       sbic   PIND,PD2      ; SW1 still closed?
    201.       rjmp   test1         ; no, return with flag = 0
    202.       sbr    Flags,sw1     ; sw1 flag <- 1
    203.       rjmp   test2         ; return with dlaf <- 1
    204. test1:
    205.       cbr    Flags,sw1     ; sw1 flag <- 0
    206. test2:
    207.       ret
    208.  
    209.  
    210. up:
    211.       ldi      r16,10
    212.       add      r25,r16
    213.       ret
    214.  
    215. down:
    216.       ldi      r16,1  
    217.       sub      r25,r16
    218.      
    219.       ret
    220.  
    221. dly:
    222.       ret
    223.       ldi      r16,0x10
    224. dly1:
    225.       ldi      r17,0xFF
    226. dly2:
    227.       dec      r17
    228.       brne    dly2
    229.       dec      r16
    230.       brne    dly1
    231.       ret
    232.  
    233.  
    234. ; Timer0 overflow interrupt service routine
    235. ; r28,r29,r30 is the phase accumulator
    236. ; r24,r25,r26 is the adder value determining frequency
    237. ;
    238.  
    239. TIMER0_OVF:
    240.       add      r28,r24      ; add value to accumulator
    241.       adc      r29,r25  
    242.       adc      r30,r26
    243.       lpm                   ; load byte from current table in ROM
    244.       out      PORTB,r0     ; output byte to port
    245.       ldi      Temp,Delay_count
    246.       out      TCNT0,Temp
    247.       reti
    248.  
    249.  
    250. TIMER1_OVF:
    251.  
    252.  
    253.       reti
    254.  
    255.  
    256. ;******************************************************************************
    257. ; data tables
    258. ;******************************************************************************
    259.  
    260.    ; force table to begin at 256 byte boundary
    261.  
    262.    .org 0x200
    263.  
    264. square:      ; 256 step squarewave table
    265.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    266.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    267.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    268.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    269.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    270.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    271.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    272.    .db   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    273.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    274.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    275.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    276.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    277.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    278.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    279.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    280.    .db   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    281.  
    282.  
    283. ;******************************************************************************
    284. ; end of file  
    285. ;******************************************************************************
    286.  
    [/code]
     
  5. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    I'm sorry to say thing is not looking good. :(

    The original designer Jesper Hansen had selected the AT90S2313 or in its replacement Tiny2313 for very good reasons. So you or someone else would think it is must be a piece of cake just to use a bigger chip like Mega8 or Mega88 to replace it, you could be in for a big surprise.

    One should be aware that the selected MCU must satisfy the following requirement:

    1. it has a 8-bit dedicated output port for the external R-2R DAC network
    2. Rx/Tx pins for serial communication with PC
    3. external crystal connection

    Unfortunate in your case you have got point 1&3 of the above requirement wrong. Pin#9 and pin#10 on the ATMega8 can be either external crystal connections or PB6 & PB7, but can't be both at the same time.

    [​IMG]

    Now the remaining full 8-bit port available on the M8 is PortD. However, using it would violate requirement 2 of the above and you have no serial communication with the PC.

    So what would be the possible solution? There are at least two.

    1. Use the Mega8 PortD to drive the external R-2R DAC, and bit-bang the serial communication in software. But this leave you with no connection of external Push Button. Or Do NOT use any serial communication at all.

    2. Use a 40-pin chip that satisfy the above requirement, like Mega16, Mega32...
     
    • DDS1.jpg
      DDS1.jpg
      File size:
      47.8 KB
      Views:
      250
    Last edited: Aug 25, 2009
  6. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    Thanks for your help.

    So, I drew up a new diagram using the

    ATMEGA16

    Let me know if the new diagram looks okay?
     
    Last edited: Aug 25, 2009
  7. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You've got the serial port (TX/RX) connected to the LCD display.
     
  8. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    Could I do:

    RS -->PC7
    RW-->PC6
    E -->PB4
    D4-->PB0
    D5-->PB1
    D6-->PB2
    D7-->PB3

    And then PD0 and PD1 will be free for the MAX202,
    and the AD557 will connect pins 0-7 to PA0-PA7.
     
    Last edited: Aug 25, 2009
  9. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Yes you can but you can also do it (better) this way.

    Port A : 8-bit, Free, for I/O or ADC use if required
    Port B : Push buttons, LCD 4-bit Data
    Port C : 8-bit DAC
    Port D : Rx, Tx, LCD controls

    Edited: With hindsight, the above will not work. The main program is running in an endless loop and external stimulus must be via interrupt to break the MCU operation. This is the amended recommendation.

    Port A : 8-bit, Free, for I/O or ADC use if required
    Port B : LCD 4-bit Data and control
    Port C : 8-bit DAC
    Port D : Rx, Tx, push buttons (PD2 & PD3)
     
    Last edited: Aug 26, 2009
  10. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    Ok how is this?

    Will these changes effect the original program?
     
  11. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    How are you going to program the Mega16 in circuit? Your current ICSP connections are all wrong. You would need proper connections to MOSI, MISO, SCK, GND & VCC pins of Mega16.

    Sure it does. You would need to change the reference of PORT in the original software to that of your new configuration.

    Also you would need additional coding to take care of the push buttons. I have overlooked the operation of the main program in allocating the pin resources in the above post. The main program is running in an endless loop and INTERRUPT must be used for external input like push button.

    It would be more appropriate to allocate the push buttons to PD2 & PD3 of PORT D instead because you can then use INT0 & INT1 on PORT D to read the push button.
     
  12. Colossus

    Thread Starter Member

    Aug 12, 2009
    18
    0
    I give up.

    I'll just use an Arduino and program it with the freqout function and buttons to generate the various frequencies.
     
  13. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Not a bad decision afterall. :)

    If you look at the following relationship between actual output frequency and the phase accumulator(r24/r25/r26) value, you would have a hard time using assembly language to calculate the frequency for display on the LCD.

    Code ( (Unknown Language)):
    1.  
    2. ;   fClock is in this case the CPU clock divided by the
    3. ;   number of cycles to output the data ( 9 cycles )
    4. ;
    5. ;   f = r24/r25/r26 * (11059200/9)/16777216
    6. ;
    7. ;   f = r24/r25/r26 * 0.073242188
    8. ;
    9. ;   f is the output frequency to be displayed on LCD
    10.  
     
Loading...