Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

(ASK)PIC to ATMEGA
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
dekorresley

Bascom Member



Joined: 13 Jul 2012
Posts: 41

indonesia.gif
PostPosted: Tue Jul 17, 2012 12:27 pm    Post subject: (ASK)PIC to ATMEGA Reply with quote

hi .. companions forum
I ask for its support.
Where as if wearing ATMega 8 ....
please help, thank you.

Code:
Device = 16f628a                                            'PIC'i tanıtıyoruz.
Config Intrc_osc_clkout , Mclre_off , Lvp_off , Wdt_off , Pwrte_off , Cp_off , Boden_off
Declare I2c_sclout On
'---------------------------LCD--------------------------------
  Lcd_dtpin = Portb.0
        Lcd_rspin = Portb.4
  Lcd_enpin = Porta.3
  Lcd_interface = 4                                         ' 4-bit Interface
  Lcd_lines = 2
  Lcd_type = 0
  Cmcon = 7

'---------------------------Adresler----------------------------
Dim Frekans_step As Word                                    'Frekans Onda sayı
Dim Frekans_tam As Word                                     'Frekans Tam sayı
Dim Frekans_onda As Word                                    'Frekans stepi
Dim Frekans As Word                                         'Frekans bilgisi değişkeni
Dim F_kontrol As Word                                       'KONTROL değikenini tanımladık
Dim Adres As Byte                                           'TSA5511 için adres değişkeni

Dim Lo As Frekans.lowbyte                                   'Frekans değişkeninin düşük byte'ı
Dim Hi As Frekans.highbyte                                  'Frekans değişkeninin yüksek byte'ı

'--------------------------Portlar------------------------------
Symbol Sda = Porta.1                                        'I2C'nin SDA'sı PORTA.1'ya bağlı
Symbol Scl = Porta.0                                        'I2C'nin Scl'si PORTA.0'ya bağlı
Symbol Led = Porta.2                                        'LED PORTA.2'e bağlı
Porta = 0 : Portb = 0                                       'PORTA ve PORTB sıfırlandı
'------------------------Eepromdan OKu--------------------------
Bas:
High Led
Print At 1 , 1 , " FM TRANSMITTER "
Print At 2 , 1 , "  Rdvv ViProje  "
Delayms 999
Adres = $c2                                                 'TSA ın adresi tanımlandı.
Frekans_step = Eread 02                                     'Frekans Deyerini EData dan okuyor.
If Frekans_step > 0 Then Tsayaz                             'Frekans Bilgisi 0 Dan Büyük ise Tsa yaza gidiyor.
'----------------------Frekans Değiştir-------------------------
Frekans_set:
'----------------------- Tsa5511 e yaz--------------------------
Frekans = Frekans_step                                      'frekans_ step in içeriğini Frekans a aktar.
I2cwrite Sda , Scl , Adres , [hi , Lo , $8e , $10]          'TSA ya yaz Kırmızı Tsa Üzerindeki Kırmızı ledi yak.

Frekans_onda = Frekans_step / / 10                          'LCD ye yazcak olan ondalık sayıyı hesapla Ör;9820//100=20
Frekans_tam = Frekans_step / 10                             'LCD ye yazcak olan tam sayıyı hesapla Ör;9820/100=98
Print At 1 , 1 , " FRE SET " , Dec Frekans_tam , "," , Dec Frekans_onda , "0 "       'LCD Yaz
Print At 2 , 1 , " RDVV 8Watt PLL "                         'LCD Yaz
Delayms 200
If Portb.5 = 1 Then Artir_frekans                           'frekans artır butonunu kontrol et
If Portb.7 = 1 Then Azalt_frekans                           'Frekans azalt butonunu kontrol et.
If Portb.6 = 1 Then Kaydet_frekans                          'Kaydet Butonunu kontrol et.

Goto Frekans_set
Artir_frekans:
            Frekans_step = Frekans_step + 1                 'içeriği 5 artir
            If Frekans_step > 10000 Then Frekans_step = 8750       'içerik 10800 dan büyük ise 8750 yap
            Goto Frekans_set
Azalt_frekans:
            Frekans_step = Frekans_step - 1                 'içeriği 5 azalt
            If Frekans_step < 8750 Then Frekans_step = 10800       'içerik 8750 den küçük ise 10800 yap
            Goto Frekans_set


'--------------------------Edataya yaz---------------------------
Kaydet_frekans:
Ewrite 02 , [frekans_step]                                  'Frekans Bilgisini Edataya yazıyor
Delayms 50
'----------------------- Tsa5511 e yaz--------------------------
Tsayaz:
Frekans_onda = Frekans_step / / 10
Frekans_tam = Frekans_step / 10
Print At 1 , 1 , " UnLock " , Dec Frekans_tam , "," , Dec Frekans_onda , "0 "       'lcd yaz
Print At 2 , 1 , " RDVV 8Watt PLL "                         'LCD Yaz
Frekans = Frekans_step
I2cwrite Sda , Scl , $c2 , [hi , Lo , $8e , $00]
Delayms 150

'----------------------Tsa5511i Kontrol et----------------------
If Portb.6 = 1 Then Frekans_set
I2cread Sda , Scl , $c2 , [f_kontrol]
If F_kontrol.6 = 1 Then Kitli
Goto Tsayaz
Kitli:
I2cwrite Sda , Scl , $c2 , [hi , Lo , $8e , $24]
Frekans_onda = Frekans_step / / 10
Frekans_tam = Frekans_step / 10
Print At 1 , 1 , "   Lock " , Dec Frekans_tam , "," , Dec Frekans_onda , "0 "       'lcd Yaz
Print At 2 , 1 , " RDVV 8Watt PLL "                         'LCD Yaz
K_buton:
Delayms 100
If Portb.5 = 1 Then Lcd_led_off
If Portb.7 = 1 Then Lcd_led_on
If Portb.6 = 1 Then Frekans_set
Goto K_buton
Lcd_led_on:
High Led
Goto K_buton
Lcd_led_off:
Low Led
Goto K_buton
End
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Wed Jul 18, 2012 3:58 pm    Post subject: Reply with quote

Here is a test you need to read bascom help file to learn more
This is just a direct translate of code , its better to make a main do - loop and sub's
no need to write to display unless you change the freq


Code:

$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 20
$framesize = 32

Config Portb.5 = Input
Config Portb.6 = Input
Config Portb.7 = Input
Config Portc.2 = Output
Config Scl = Portc.5
Config Sda = Portc.4
Config I2cdelay = 20
I2cinit



'setup lcd  EDIT THIS TO YOUR LCD SETUP

Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 16 * 2
Cursor Off Noblink
Cls



Dim Frekans_step As Word
Dim Frekans_tam As Word
Dim Frekans_onda As Word
Dim Frekans As Word


Dim Lo As Byte
Dim Hi As Byte

Const Adres = &HC2

Led Alias Portc.2
Portb = 0
'Frekans_step = 982 test only
'Writeeeprom Frekans_step , 02 test only
Main:
Set Led
Locate 1 , 1
Lcd " FM TRANSMITTER "
Locate 2 , 1
Lcd "  Rdvv ViProje  "
Waitms 999

Readeeprom Frekans_step , 02
If Frekans_step > 0 Then Goto Tsayaz


Frekans_set:
Frekans = Frekans_step
Lo = Low(frekans)
Hi = High(frekans)

I2cstart
I2cwbyte Adres
I2cwbyte Hi
I2cwbyte Lo
I2cwbyte &H8E
I2cwbyte &H10
I2cstop
Waitms 10


Frekans_onda = Frekans_step Mod 10
Frekans_tam = Frekans_step / 10

Locate 1 , 1
Lcd " FRE SET " ; Val(frekans_tam) ; "," ; Val(frekans_onda) ; "0 "

Locate 2 , 1
Lcd " RDVV 8Watt PLL "
Waitms 200

If Pinb.5 = 1 Then Goto Artir_frekans
If Pinb.7 = 1 Then Goto Azalt_frekans
If Pinb.6 = 1 Then Goto Kaydet_frekans

Goto Frekans_set

Artir_frekans:
   Frekans_step = Frekans_step + 1
   If Frekans_step > 10800 Then Frekans_step = 8750
   Goto Frekans_set

Azalt_frekans:
   Frekans_step = Frekans_step - 1
   If Frekans_step < 8750 Then Frekans_step = 10800
   Goto Frekans_set

Kaydet_frekans:
Writeeeprom Frekans_step , 02
Waitms 50

Tsayaz:
   Frekans_onda = Frekans_step Mod 10
   Frekans_tam = Frekans_step / 10
   Cls
   Locate 1 , 1
   Lcd " UnLock " ; Frekans_tam ; "," ; Frekans_onda ; "0 "
   Locate 2 , 1
   Lcd " RDVV 8Watt PLL "
   Frekans = Frekans_step
   I2cstart
   I2cwbyte Adres
   I2cwbyte Hi
   I2cwbyte Lo
   I2cwbyte &H8E
   I2cwbyte &H00
   I2cstop

   Waitms 150


If Pinb.6 = 1 Then Goto Frekans_set

I2cstart
I2cwbyte Adres
I2crbyte F_kontrol , Nack
I2cstop
Waitms 25

If F_kontrol.6 = 1 Then Goto Kitli
Goto Tsayaz

Kitli:
I2cstart
I2cwbyte Adres
I2cwbyte Hi
I2cwbyte Lo
I2cwbyte &H8E
I2cwbyte &H24
I2cstop
Waitms 10

Frekans_onda = Frekans_step Mod 10
Frekans_tam = Frekans_step / 10
Locate 1 , 1
Lcd "   Lock " ; Val(frekans_tam) ; "," ; Val(frekans_onda) ; "0 "

Locate 2 , 1
Lcd " RDVV 8Watt PLL "


K_buton:
Waitms 100
If Pinb.5 = 1 Then Goto Lcd_led_off
If Pinb.7 = 1 Then Goto Lcd_led_on
If Pinb.6 = 1 Then Goto Frekans_set
Goto K_buton

'----------------------
Lcd_led_on:
Set Led
Goto K_buton

'----------------------
Lcd_led_off:
Reset Led
Goto K_buton
End

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
dekorresley

Bascom Member



Joined: 13 Jul 2012
Posts: 41

indonesia.gif
PostPosted: Thu Jul 19, 2012 12:00 pm    Post subject: Reply with quote

hi .. Mr.Kim
I've tried to use the Atmega 8 IC and I've added its drawbacks, namely:

Code:
Dim F_kontrol As Word


but why it still does not appear to LCD
compile but it was OK ..
please you the solution .. Rolling Eyes
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Thu Jul 19, 2012 9:37 pm    Post subject: Reply with quote

Hi,
Yes a error in read address
by mistake I used write address (R/W bit 0) for read it must be set to 1 Hex C2 must be C3

Dim F_kontrol as byte '



Code:
I2cstart
I2cwbyte &HC3  ' WAS adres (C2)
I2crbyte F_kontrol , Nack
I2cstop
Waitms 25


Or you can try the addon file PLL.Bas
it use I2csend command
its from a old code with PLL U6205B - SP5055

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
ardydarwys

Bascom Member



Joined: 08 Jun 2014
Posts: 9

indonesia.gif
PostPosted: Sat Jun 28, 2014 6:31 pm    Post subject: Reply with quote

Question Question Question Question Question where N value to setting???
ex calculate in 100 mhz
3,2Mhz/512 = 6,25khz signal reference
100mhz/8 = 12,5 mhz

12,5mhz/6,25khz= 2000
Back to top
View user's profile
ardydarwys

Bascom Member



Joined: 08 Jun 2014
Posts: 9

indonesia.gif
PostPosted: Sat Jun 28, 2014 6:34 pm    Post subject: Reply with quote

where?
Question
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Mon Jun 30, 2014 2:18 am    Post subject: Reply with quote

the code you show is setup for 6.4Mhz xtal ad 100 Khz steps

see datasheet

Quote:
The 7.8125 kHz reference frequency is obtained by dividing the output of the 4 MHz crystal oscillator by 512. Because
the input of UHF/VHF signal is first divided by 8 the step size is 62.5 kHz.

A 3.2 MHz crystal can offer step sizes of 50 kHz.

3200/512 = 6.25 Khz * 8 = 50 Khz

pll value 1750 - 2160 = 87.5 - 108 Mhz
see addon bas

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
ardydarwys

Bascom Member



Joined: 08 Jun 2014
Posts: 9

indonesia.gif
PostPosted: Mon Jun 30, 2014 2:15 pm    Post subject: Reply with quote

thanks mr.kim..
Back to top
View user's profile
ardydarwys

Bascom Member



Joined: 08 Jun 2014
Posts: 9

indonesia.gif
PostPosted: Mon Jun 30, 2014 6:57 pm    Post subject: Reply with quote

work

hore...hore...hore..
thank mr.kimmi Razz Razz Razz Very Happy Very Happy Very Happy Very Happy Very Happy
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Jul 01, 2014 1:16 am    Post subject: Reply with quote

Nice !!

A small fix in code
delete this red text :
Freq_lcd = Frekans_step * 50
Freq_lcd = Freq_lcd /1000

use this
Freq_lcd = Frekans_step * 0.05

no need to div by 1000

I was a bit sleepy when i edit the code Smile

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
ardydarwys

Bascom Member



Joined: 08 Jun 2014
Posts: 9

indonesia.gif
PostPosted: Tue Jul 01, 2014 5:57 pm    Post subject: Reply with quote

Mr. I want to ask the result of the following code on the can of formula where and how where how to find out. thank you.

Pll = Frekans_step
Pll_msb = High(pll)
Pll_lsb = Low(pll)
Ax(1) = Pll_msb
Ax(2) = Pll_lsb
Ax(3) = &H8E <<<?
Ax(4) = &H10 <<<?
Snd_bytes = 4
I2csend Address_write , Ax(1) , Snd_bytes
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1534
Location: Basel, Switzerland

switzerland.gif
PostPosted: Tue Jul 01, 2014 7:15 pm    Post subject: Reply with quote

Hello

&H means the value is a hex number, so
&H8E = 142 (decimal)
&H10 = 16 (decimal)

Regards
Ian Dobson

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Jul 01, 2014 9:00 pm    Post subject: Reply with quote

see datasheet page 7 byte 4 & 5

Charge-pump and test bits
and
Output ports control bits

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
dekorresley

Bascom Member



Joined: 13 Jul 2012
Posts: 41

indonesia.gif
PostPosted: Tue Jul 01, 2014 9:07 pm    Post subject: Reply with quote


    Pll = Frekans_step
    Pll_msb = High(pll)
    Pll_lsb = Low(pll)
    Ax(1) = Pll_msb
    Ax(2) = Pll_lsb
    Ax(3) = &H8E <<<?
    Ax(4) = &H10 <<<?
    Snd_bytes = 4
    I2csend Address_write , Ax(1) , Snd_bytes



may mean that the address is in Datasheet TSA 5511
& H8E = 142 (decimal) <<<???
& H10 = 16 (decimal) <<<???
The can of where and how where how to determine it.?

_________________
https://www.facebook.com/dekorresley
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Jul 01, 2014 10:21 pm    Post subject: Reply with quote

&H8E = binary 10001110

Charge-pump
and test bits
1 CP T1 T0 1 1 1 OS
1 0 0 0 1 1 1 0 (&H8E)

CP charge-pump current
CP = 0 50 µA
CP = 1 220 µA
P3 to P0 = 1 limited-current output is active
P7 to P4 = 1 open-collector output is active
P7 to P0 = 0 outputs are in high impedance state
T1, T0, OS = 0 0 0 normal operation
T1 = 1 P6 = fref, P7 = fDIV
T0 = 1 3-state charge-pump
OS =1 operational amplifier output is switched off (varicap drive disable)

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum