Wednesday, 09 July 2025
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #160 - Camera project with M162 Print
Fedor Sumkin , Russia , 2007

Here is little project, which in the next once proves the superiority a controller AVR on rest processor.

When enabling device, is initialized screen, is flooded by black colour and is removed video real-time with cameras.

The Iron:

The Camera ADCM1700 rs from telephone Siemens S65 (their there several types it is necessary to take with inscription HERA 0408) Controller ATMEGA162 - 16PU. Possible drive before 24 megahertz (the body of the quartz fastened on mass, so more works).

The Display from Siemens S65 with controller LPH8836 (other display with the other controller to put no sense in view of their different commands to initialization) MEGA clock the camera by conclusion OC1A frequency 8 megahertz. Also with cameras come the signals to synchronizing hsync and vsync, which are hooked on  interruptions of the controller.

The Display hungs on bus SPI, which is dispersed before limit, and basically influences upon the whole capacity device.

Feeding of device 3 volt.

Feeding of highlight display 12 volt.

Schematic:


 

Detail:





Program:

'-------------------------------------------------------------------------------
' Connection a display Siemens S65 with marking Lph88  for Atmega162
'-------------------------------------------------------------------------------
'   illumination display 12 volt ( be carefull ).
'
'                    LCD            AVR
'                    ---            ---
'                    1 /RS          B4
'                    2 /Reset       B3
'                    3 /CS          B2
'                    4 /CLK         B7
'                    5 /DAT         B5
'                    6 /Vcc        3 V (max.3.3 V, min.2.4 V)
'                    7 /GND        GND
'                    8 /Vdigital   3 Volt
'                    9 /LED+       12.0 V
'                    10/LED-       GND
'-------------------------------------------------------------------------------
'
'   Program of functioning with display Siemens c65
'
'-------------------------------------------------------------------------------
'                  Bascom-AVR 1.11.8./...
'-------------------------------------------------------------------------------
$regfile = "m162def.dat" 'MEGA 162
$crystal = 16000000                                         'quartz 24 megahertzs will correct position of deals
$baud = 115200                                              'velocity COM port 115200 (for overclocking REM)

$hwstack = 16
$swstack = 16
$framesize = 32
'$xramstart = &H260
'$xramsize = 65535
'
On Int0 Data_reqest Nosave
On Int1 Hsyncro Nosave 'duration of line forms 319 microseconds
 'break between lines forms 114 microseconds (productive time)
On Int2 Kadr Nosave 'duration of frame forms 207 milliseconds
'///////////////////////////////////////
'For normal work with memory put latch cameras in unit.
'///////////////////////////////////////
Wait 2
Ddrb = &B11111111                                           'port b on output

Config Timer1 = Counter , Prescale = 1 , Compare A = Toggle 'give a clockrate on camera
Set Tccr1b.wgm12
Set Tccr1b.wgm13

Reset_memory Alias Portd.: Set Ddrd.7
Select_memory Alias Portd.: Set Ddrd.6
Camera_latch Alias Porte.: Set Ddre.2
Camera_ale Alias Portb.: Set Ddrb.0
Rs Alias Portb.4                                            '
Rst Alias Portb.3                                           '
Cs Alias Portb.2
Clk Alias Portb.7
Dat Alias Portb.5
Vsync Alias Pine.: Reset Ddre.0                           '
Hsync Alias Pind.: Reset Ddrd.3                           '
Data_clk Alias Pind.: Reset Ddrd.2
'Adjust ports on input/output
Set Ddrd.1
Config Portc = Input

Const Buff1_write = &H84
Const Buff2_write = &H87
Const Buff1_mem_write = &H83
Const Buff2_mem_write = &H86
Const Current_page_read = &HD2
'Colour Constants for display (I their until use)
Const White = &HFFFF                                        'white
Const Black = &H0000                                        'black
Const Red = &HF800                                          'red
Const Green = &H7C0                                         'green
Const Blue = &H1F                                           'blue
Const Whiblu = &H7FF                                        'whiblu
'Dim Adr As Word
Dim Xt As Byte
' For itself several variable
Dim Temp As Byte , X As Byte , Y As Byte , C As Bit
Dim Buf(264) As Byte At &H120                               ' buffer for one line a display, also buffer an flash
Dim Page_mem As Word , Ar As Bit
Dim A As Word , N As Byte , Temp1 As Word
Dim Cadr_counter As Word
'It is Necessary to describe several subroutines
Declare Sub Bytein()
Declare Sub Clear_screen(byval Clear_color As Word)
Declare Sub Wordout()
Declare Sub Byteout()
Declare Sub S65_init()
Declare Sub Window_locate(byval X_start As Byte , Byval Y_start As Byte , Byval X_end As Byte , Byval Y_end As Byte)
Declare Sub Cspulse()
Declare Sub Command_send(byval Nn As Byte)
Declare Sub Data_send(byval Aa As Word)
Declare Sub Page_read(byval Page_mem As Word)
Declare Sub Buffer1_to_flash(byval Page_mem As Word)
Declare Sub Buffer1_write
= 1 : A = 1
Config Int1 = Rising
Config Int2 = Rising
'Config Int0 = Falling
Const Cam_addr = &HA2
Const Reg = &H000A
Config Spi = Hard , Interrupt = On , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
Spiinit
Reset Spcr.spr1 : Reset Spcr.spr0 : Set Spsr.spi2x
'initialized SPI
Call S65_init
Call Clear_screen(black)
Set Cs
'$asm
'Sbi portb,0                                                 'free bus given (have switched off camera)
'Sbi Mcucr,7
'$end Asm
Call Window_locate(, 1 , 127 , 176) 'added such useful subroutine (possible expose size of window)
$asm
ldi yh,$03
ldi yl,$00
clr r0
ldi r18,0
$end Asm
Enable Interrupts
Enable Int2 'interruption on beginning of line
Gr:
'-------------Here is this piece of code is adjusted on transmission of line so that skip  the whole one line------------------
If C = 0 Then
$asm
.def Temp = R22
.def Out1 = R21
.def Out2 = R20

cli
ldi r17,$7f
Dr:
 ld r23,y+

'--------------
 mov temp,r23
 !swap temp
 andi temp,$f
'--------------

'----------------
 '   mov temp,r23
 '  !Swap Temp
 '  lsr     temp
 '   andi temp,$7
 '   mov out1,r23
 '   andi out1,$f9
 '   add out1,temp
'-----------------

!out spdr,temp

Waih:
 sbis spsr, spif
 rjmp waih
';     mov temp,r23
 '   mov out2,r23
 '  lsr out2
 '   lsr out2
 '   lsr out2
 '   lsr r23
 '  !swap r23

 '   andi  r23,$e0
 '    andi  out2,$1f
 '    add out2,temp
 !out spdr,temp

Wapih:
 sbis spsr, spif
 rjmp wapih
 ld r23,y+
 dec r17
 brne  DR

'removed one line
$end Asm
= 1
sei
End If
Goto Gr
'-----------------------------------------------------------------------------------------------------------------------
End

Sub Bytein()
 ldi r23,0
 !Out Spdr , R23
Wairh:
 sbis spsr, spif
 rjmp wairh
 in r23,spdr
 sts {n},r23
End Sub

'--------------------subroutines---------------------
'###############################################################################
Sub Cspulse                                                 'short pulse CS
 Set Cs
 nop
 Reset Cs
End Sub

'------------Issue of just command an display---------------------------
Sub Command_send(byval Nn As Byte) 'issue of command
= &H74
Call Byteout()
= 0
Call Byteout()
= Nn
Call Byteout()
Call Cspulse
End Sub
'----------Issue of just data an display------------------------------
Sub Data_send(byval Aa As Word) 'issue of Data
= &H76
Call Byteout()
= Aa
Call Wordout()
Call Cspulse
End Sub
'--------Subroutine for issue of parameter or spot in display----------------
Sub Wordout
 lds r23, {a+1}
 !out spdr, r23
 lds r23, {a}
Wait_trh:
 sbis spsr, spif
 rjmp wait_trh
 !out spdr, r23
Wait_trl:
 sbis spsr, spif
 rjmp wait_trl
End Sub

'-------------Subroutine for parcel a command an display--------------------------
Sub Byteout
 lds r23, {n}
 !out spdr, r23
 Waitresult:
 sbis spsr, spif
 rjmp waitresult
End Sub

'-------------------------------------------------------------------------------
Sub S65_init
Reset Rst
Set Cs
Set Rs
Waitms 1
Set Rst
Waitms 10
Reset Cs
Restore Ini_code
For Temp = 0 To 33
Read N
Call Command_send(n)
Read A
Call Data_send(a)
Next Temp
Waitms 300
Set Cs
End Sub
'-------------------------------------------------------------------------------

Sub Clear_screen(clear_color As Word)
Dim Temp2 As Word

Reset Cs

Call Command_send(&H16)
Call Data_send(&H8400) 'Interesting parameters to reference (131) end on ő
Call Command_send(&H17)
Call Data_send(&Haf00)
Call Command_send(&H21) 'here expose window, in which remove to info.
Call Data_send(&H0)
Call Command_send(&H22)
= &H76
Call Byteout()
= Clear_color

For Temp2 = 1 To 46464
Call Wordout()
Next Temp2

End Sub

Sub Window_locate(As Byte , Y As Byte , X_pixel As Byte , Y_pixel As Byte)
'subroutine Window locate
'first parameter - horizontal initial coordinate
'second parameter - vertical initial coordinate
'third parameter - horizontal end coordinate
'fourth parameter - vertical end coordinate
'Space is calculated so:
' (horizontal end coordinate - horizontal initial coordinate)
' multiply by
' (vertical end coordinate - vertical initial coordinate)

Reset Cs

Call Command_send(&H16)

= &H76
Call Byteout()
= X_end
Call Byteout()
= X_start
Call Byteout()
Call Cspulse

Call Command_send(&H17)
= &H76
Call Byteout()
= Y_end
Call Byteout()
= Y_start
Call Byteout()
Call Cspulse

Call Command_send(&H21)
= &H76
Call Byteout()
= X_start                                                 'On my here changed (X and Y) but in such type works too
Call Byteout() 'In ideal needed to change
= Y_start
Call Byteout()
Call Cspulse

Call Command_send(&H22)
= &H76
Call Byteout()
End Sub

'-------------------------------------------------------------------------------
Sub Page_read(byval Page_mem As Word)
'-------------Flash read subroutine---------------------------------------------
'Subroutine of reading given pages of memory
'Input-------page_Mem (0-2047)
'Output------buf(264) ěŕńńčâ 264 áŕéňŕ
Reset Select_memory                                         'select flash ram
= Current_page_read                                       'command Current_page_read
Call Byteout() 'out 3 bytes of adress
Shift Page_mem , Left , 1

= Page_mem
Call Wordout()
= 0
Call Byteout()
'-------------
Call Byteout()
Call Byteout()
Call Byteout()
Call Byteout()
'ďĺđĺäŕëč 32 dont care bits
For Temp1 = 1 To 264
Call Bytein()
Buf(temp1) = N
Next Temp1
Set Select_memory
End Sub

Sub Buffer1_to_flash(byval Page_mem As Word)
'-------------Flash write subroutine---------------------------------------------
'Subroutine of writing a buffer 1 in page of memory
'Input-------page_Mem (0-2047)
Reset Select_memory
= Buff1_mem_write                                         ' command write buffer to flash
Call Byteout()
Shift Page_mem , Left , 1

= Page_mem
Call Wordout()
= 0
Call Byteout()
Set Select_memory                                           'deselect memory
Waitms 30
End Sub

Sub Buffer1_write
Reset Select_memory
= Buff1_write                                             ' command write in buffer
Call Byteout()
= &H00                                                    '
Call Byteout()
= &H00                                                    '
Call Byteout()
= &H00                                                    '
Call Byteout()
'Set Select_memory
End Sub

Data_reqest:

$asm

in r23,Pinc

st y+,r23
dec r19
breq all

reti

All:
ldi r19,$c0
ldi yh,$03
ldi yl,$00
$end Asm
Disable Int0
= 0

Return

Hsyncro:
$asm
 ldi yh,$03
 ldi yl,$00
 ldi r19,$c0
$end Asm
Enable Int0 'take line in buffer
Return

Kadr:
Call Window_locate(, 1 , 127 , 176)
= 1
Incr Cadr_counter
Enable Int1

Return

Ini_code:
Data &H07 , &H0000% , &H02 , &H0400% , &H04 , &H0000% , &H0C , &H0001% , &H0D , &H0616% , &H0E , &H1010%
Data &H03 , &H000C% , &H0E , &H2D1F% , &H0D , &H0616% , &H01 , &H0215% , &H0F , &H0000% , &H0B , &H0000%
Data &H11 , &H0000% , &H06 , &H0000% , &H05 , &H0030% , &H14 , &HAF00% , &H15 , &H0000% , &H16 , &H8300%
Data &H17 , &HAF00% , &H20 , &H0000% , &H30 , &H0000% , &H31 , &H0400%
Data &H32 , &H0207% , &H33 , &H0700% , &H34 , &H0005% , &H35 , &H0703% , &H36 , &H0707% , &H37 , &H0007%
Data &H3A , &H1200% , &H3B , &H0009% , &H07 , &H0005% , &H07 , &H0025% , &H07 , &H0027% , &H07 , &H0037%