Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20599

Share your working BASCOM-AVR code here : ATMEGA with 433 Mhz Modules RADIOMETRIX TX2/RX2 : NEWTOPIC

$
0
0
Hello everyone, Does someone have a BASCOM code share to drive RAdio Modules 433 Mhz in RADIOMETRIX reference TX2 (Transmitter) and RX2 (Receiver). The aim being to transfer data via radio using the RX and TX pins of ATMEGA (PD.0/RX and PD.1/TX for ATMEGA 16). I tried a code but it does not seem to work. My code works if I connect the TX and RX wired part ... but when I replace the son by radio modules does not work. Maybe he should filter out the noise with a code in the ATMEGA? If not I can post my code and schematic if someone wants to help me. I have seen similar mounts on the WEB with ARDURINO, it should be possible with BASCOM ... [code:1:fe874b7a89]//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// HARDWARE : '----- Modules Radio RADIOMETRIX TX2 et RX2 ---------------------------------------- '>>>L'emeteur Radio utilisé dans ce montage est le TX2 de chez RADIOMETRIX 'UHF FM Data Transmitter ' ' 1 2 3 4 5 ' |-o-o-o-o-o-o-o-o-o-o-o-o-| ' |-------------------------| '1 - RF Ground >Wire green '2 - RF Out (Antenna 50 Ohms) >Wire blue '3 - Vcc (+5V) >Wire red '4 - 0V >Wire black '5 - TXD (Datas) >Wire yellow ' '>>>Le recepteur Radio utilisé dans ce montage est le RX2 de chez RADIOMETRIX 'UHF FM Data Receiver ' ' 1 2 3 4 5 6 7 ' |-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-| ' |-------------------------------------| '1 - RF Out (Antenna 50 Ohms) >Wire blue '2 - RF Ground >Wire green '3 - CD (+5V) >Wire red '4 - 0V >Wire black '5 - Vcc (+3V) >Wire red '6 - AF (Not use) '7 - RXD (Datas) >Wire yellow ' '>>>>>>>> ASTUCE DOUBLE IMPLANTE (RX ou TX) ' TX2 1 2 3 4 5 ' RX2 1 2 3 4 5 6 7 ' |-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-| ' |-------------------------------------| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////[/code:1:fe874b7a89] RECEPTOR CODE : [code:1:fe874b7a89]'***************************** 1- Directives *********************************** 'Directives are special instructions for the compiler. They can override a setting from the IDE. 'Les directives sont des instructions spéciales pour le compilateur. Ils peuvent remplacer un paramètre dans l'IDE. 'Définition du type de processeur (! le fichier .dat doit exister dans le path) $regfile = "m16def.dat" 'Définition de la vitesse de la clock a 8.0 Mhz $crystal = 8000000 '$hwstack = 32 ' default use 32 for the hardware stack '$swstack = 10 ' default use 10 for the SW stack '$framesize = 40 ' default use 40 for the frame space 'Définition de la vitesse du port série '$baud = 9600 'Activer ou desactiver la simulation '$sim 'Le port JTAG est activé par defaut mais il est possible d'utiliser les pins PORTC.2 à PORTC.5 'Utiliser le code de désactivation du JTAG ci-dessous Mcusr = &H80 Mcusr = &H80 '***************************** 2- Configuration ******************************** 'Configuration commands initialize the hardware to the desired state. 'Commandes de configuration, initialise le matériel à l'état désiré. Config Porta = Output 'Port affichage LCD Config Portb = Input 'Port entree Switch SW1 a SW4 Config Portb.4 = Output Config Portb.6 = Output Config Portb.7 = Output 'Et Activer Les Résistances De Pull Up(pour Avoir 1 Qd Le Switch n'est pas enfoncé) Portb = 255 Portb.6 = 0 Portb.7 = 0 Config Portc = Output 'Port sortie LED1 a LED8 ou Bornier PC0 a PC7 'PortC = 255 Config Portd = Input Config Portd.3 = Input 'Port entree recepteur infrarouge Config Portd.5 = Output 'Port sortie led infrarouge Config Portd.2 = Output 'Port sortie Retro-eclairage afficheur / Ledbacklight 'Config 1wire = PortC.2 '*********************************** Afficheur LCD NOKIA 3310 ****************** 'Config Spi = Soft , Din = Porta.0 , Dout = Porta.3 , Ss = None , Clock = Porta.2 'Lcd_cmd Alias Porta.4 'Low for cmd mode 'Lcd_cs Alias Porta.5 'Low for lcd enable 'Lcd_res Alias Porta.1 'Low for reset 'LCD pin AVR Port.pin 'SCLK(2) PortD.4 - PA2. 'SDIN(3) PortD.5 - PA3. 'D/C(4) PortD.6 - PA4 'SCE(5) PortD.7 - PA5 'RESET(8) PortD.3 - PA1 '*********************************** Afficheur LCD 4*20 ************************ Config Lcdmode = Port ' config le LCD en 4 bit Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0 Config Lcd = 20 * 4 ' PIN mode with 4-bit ' Vss 1 - GND ' Vdd 2 - VCC +5 Volt ' Vo 3 - 0-VCC Contrast ' RS 4 - PC0 - PA0 ' RW 5 - GND ' E 6 - PC2 - PA1 ' Db0 7 - NC ' Db1 8 - NC ' Db2 9 - NC ' Db3 10 - NC ' Db4 11 - PC3 - PA2 ' Db5 12 - PC4 - PA3 ' Db6 13 - PC5 - PA4 ' Db7 14 - PC6 - PA5 '***************************** 3- Variables / Alias **************************** 'Dimension all required variables and Alias. 'Definition et valeures des variables requises et des Alias. Redled Alias Portb.7 Greenled Alias Portb.6 Buzzer Alias Portb.4 Ledbacklight Alias Portd.2 Led1 Alias Portc.0 Led2 Alias Portc.1 Led3 Alias Portc.2 Led4 Alias Portc.3 Led5 Alias Portc.4 Led6 Alias Portc.5 Led7 Alias Portc.6 Led8 Alias Portc.7 Sw1 Alias Pinb.1 Sw2 Alias Pinb.0 Sw3 Alias Pinb.2 Sw4 Alias Pinb.3 Set Ledbacklight '§§§§§§§§§§§§§§§§§§§§§ RECEPTEUR §§§§§§§§§§§§§§§§§§§§§ '***************************** 4-Main Program ********************************** 'Contains all executive instructions such as: Mathematical Instruction. 'Contient toutes les instructions, c'est le programme principal. $baud = 9600 'Format octets : 9600 Bds, 8 Bits, parité none, 1 Bits stop Initlcd Cls Cursor Off Locate 1 , 1 Lcd "TEST KITDEV V6.0 R1 " Locate 2 , 1 Lcd " RADIO RECEPTOR " Locate 3 , 1 Lcd " ((( 433 Mhz ))) " Locate 4 , 1 Lcd "Hello " Wait 3 'Sound Buzzer , 200 , 200 'Set Redled Cls 'RX 'Indésirable, truc... Dim Junk As Byte 'Synchronisation de la communication Dim Synch As Byte 'Température 1 Dim Temp1 As Byte 'Température 2 Dim Temp2 As Byte 'Enable Interrupts Start1: Cls 'CLEAR THE LCD DISPLAY Locate 1 , 1 Lcd "Out of Synch" Gosub Rxledr Start2: Locate 4 , 1 : Lcd "COM : 9600,8,n,1" 'Input , Junk : Waitms 20 'was 20ms at 2400 baud Input , Synch : Waitms 20 'Synch = 127 If Synch <> 127 Then Goto Start1 : Waitms 20 Gosub Aff Input , Temp1 : Waitms 20 'Temp1 = Rnd(100) Gosub Aff Input , Temp2 : Waitms 20 'Temp2 = Rnd(9) Gosub Aff Goto Start2 End 'end program '***************************** 5- Sub Routines ********************************* 'They are sub programs or sub procedures, call from the main program 'Ce sont les sous-programmes ou sous des procédures, qui sont appelées à partir du programme principal Rxledg: 'led for TX Set Greenled Waitms 50 Reset Greenled Return Rxledr: 'led for TX Set Redled Waitms 50 Reset Redled Return Aff: Cls 'CLEAR THE LCD DISPLAY Locate 1 , 1 : Lcd "Temp1 :" ; Temp1 'show the test as a temperatur Locate 2 , 1 : Lcd "Temp2 :" ; Temp2 Locate 4 , 1 : Lcd "COM : 9600,8,n,1" Gosub Rxledg Return '-------------------------------------------------------------------------------[/code:1:fe874b7a89] //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EMITOR CODE : [code:1:fe874b7a89]'***************************** 1- Directives *********************************** 'Directives are special instructions for the compiler. They can override a setting from the IDE. 'Les directives sont des instructions spéciales pour le compilateur. Ils peuvent remplacer un paramètre dans l'IDE. 'Définition du type de processeur (! le fichier .dat doit exister dans le path) $regfile = "m16def.dat" 'Définition de la vitesse de la clock a 8.0 Mhz $crystal = 8000000 '$hwstack = 32 ' default use 32 for the hardware stack '$swstack = 10 ' default use 10 for the SW stack '$framesize = 40 ' default use 40 for the frame space 'Définition de la vitesse du port série '$baud = 9600 'Activer ou desactiver la simulation '$sim 'Le port JTAG est activé par defaut mais il est possible d'utiliser les pins PORTC.2 à PORTC.5 'Utiliser le code de désactivation du JTAG ci-dessous Mcusr = &H80 Mcusr = &H80 '***************************** 2- Configuration ******************************** 'Configuration commands initialize the hardware to the desired state. 'Commandes de configuration, initialise le matériel à l'état désiré. Config Porta = Output 'Port affichage LCD Config Portb = Input 'Port entree Switch SW1 a SW4 Config Portb.4 = Output Config Portb.6 = Output Config Portb.7 = Output 'Et Activer Les Résistances De Pull Up(pour Avoir 1 Qd Le Switch n'est pas enfoncé) Portb = 255 Portb.6 = 0 Portb.7 = 0 Config Portc = Output 'Port sortie LED1 a LED8 ou Bornier PC0 a PC7 'PortC = 255 Config Portd = Input Config Portd.3 = Input 'Port entree recepteur infrarouge Config Portd.5 = Output 'Port sortie led infrarouge Config Portd.2 = Output 'Port sortie Retro-eclairage afficheur / Ledbacklight 'Config 1wire = PortC.2 '*********************************** Afficheur LCD NOKIA 3310 ****************** 'Config Spi = Soft , Din = Porta.0 , Dout = Porta.3 , Ss = None , Clock = Porta.2 'Lcd_cmd Alias Porta.4 'Low for cmd mode 'Lcd_cs Alias Porta.5 'Low for lcd enable 'Lcd_res Alias Porta.1 'Low for reset 'LCD pin AVR Port.pin 'SCLK(2) PortD.4 - PA2. 'SDIN(3) PortD.5 - PA3. 'D/C(4) PortD.6 - PA4 'SCE(5) PortD.7 - PA5 'RESET(8) PortD.3 - PA1 '*********************************** Afficheur LCD 4*20 ************************ Config Lcdmode = Port ' config le LCD en 4 bit Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0 Config Lcd = 20 * 4 ' PIN mode with 4-bit ' Vss 1 - GND ' Vdd 2 - VCC +5 Volt ' Vo 3 - 0-VCC Contrast ' RS 4 - PC0 - PA0 ' RW 5 - GND ' E 6 - PC2 - PA1 ' Db0 7 - NC ' Db1 8 - NC ' Db2 9 - NC ' Db3 10 - NC ' Db4 11 - PC3 - PA2 ' Db5 12 - PC4 - PA3 ' Db6 13 - PC5 - PA4 ' Db7 14 - PC6 - PA5 '***************************** 3- Variables / Alias **************************** 'Dimension all required variables and Alias. 'Definition et valeures des variables requises et des Alias. Redled Alias Portb.7 Greenled Alias Portb.6 Buzzer Alias Portb.4 Ledbacklight Alias Portd.2 Led1 Alias Portc.0 Led2 Alias Portc.1 Led3 Alias Portc.2 Led4 Alias Portc.3 Led5 Alias Portc.4 Led6 Alias Portc.5 Led7 Alias Portc.6 Led8 Alias Portc.7 Sw1 Alias Pinb.1 Sw2 Alias Pinb.0 Sw3 Alias Pinb.2 Sw4 Alias Pinb.3 Set Ledbacklight '§§§§§§§§§§§§§§§§§§§§§ EMETEUR §§§§§§§§§§§§§§§§§§§§§ '***************************** 4-Main Program ********************************** 'Contains all executive instructions such as: Mathematical Instruction. 'Contient toutes les instructions, c'est le programme principal. $baud = 9600 'Format octets : 9600 Bds, 8 Bits, parité none, 1 Bits stop Initlcd Cls Cursor Off Locate 1 , 1 Lcd "TEST KITDEV V2.0 R0 " Locate 2 , 1 Lcd " RADIO TRANSMITTER " Locate 3 , 1 Lcd " ((( 433 Mhz ))) " Locate 4 , 1 Lcd "Hello " Wait 3 'Sound Buzzer , 200 , 200 Gosub Rxledr Cls 'TX 'Indésirable, truc... Dim Junk As Byte 'Synchronisation de la communication Dim Synch As Byte 'Température 1 Dim Temp1 As Byte 'Température 2 Dim Temp2 As Byte Junk = 126 Synch = 127 Temp1 = 0 Temp2 = 255 Wait 1 Do 'temp1/2 as random number for simulate temperatur 0.0 - 100.9 Temp1 = Rnd(100) Temp2 = Rnd(9) Gosub Xmit Gosub Aff Gosub Rxledg 'led for TX ' here in test we sent it fast 'normaly you dont need to sent it every 50ms Wait 2 Loop End Xmit: Print ; Junk : Waitms 20 Print ; Synch : Waitms 20 Print ; Temp1 : Waitms 20 Print ; Temp2 : Waitms 20 Return End 'end program '***************************** 5- Sub Routines ********************************* 'They are sub programs or sub procedures, call from the main program 'Ce sont les sous-programmes ou sous des procédures, qui sont appelées à partir du programme principal Rxledg: 'led for TX Set Greenled Waitms 50 Reset Greenled Return Rxledr: 'led for TX Set Redled Waitms 50 Reset Redled Return Aff: Locate 1 , 1 Lcd "Synch : " ; Synch Locate 2 , 1 Lcd "Temp1 : " ; Temp1 Locate 3 , 1 Lcd "Temp2 : " ; Temp2 Locate 4 , 1 : Lcd "COM : 9600,8,n,1" Return '-------------------------------------------------------------------------------[/code:1:fe874b7a89]

Viewing all articles
Browse latest Browse all 20599

Trending Articles