AVR and LC72131
AVR and LC72131
Sunday
Jun 16th 5PM, during which time the login service will be impacted. Please keep your usage in VIEW ONLY
mode until the site maintenance is completed. Thanks for your understanding!
Forums (/s/forums)
Welcome to the AVR Freaks Community
Log In / Register (https://www.avrfreaks.net/services/auth/sso/Community_portal_oAuth?
The premier community for all things 8 and 32-bit AVR microcontrollers.
startURL=%2Fs%2Ftopic%2Fa5C3l000000UcRUEA0%2Ft161564)
AUTHOR
TOPIC
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
19 Comments
Author Posted: 11 Jun 2021 - 07:13 PM Last Updated: 11 Jul 2021 - 08:20 AM #1 0 0
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
//------------------------------------------------------------------------------
static void lc72131_cmd(uint8_t cmd, uint8_t data1, uint8_t data2, uint8_t data3)
{
// send address
spi_send(cmd);
// wait tEL (750 ns)
_delay_us(0.75);
// set CE
LC72131_PORT |= LC72131_CE;
// wait tES (750 ns)
_delay_us(0.75);
// send data
spi_send(data1);
spi_send(data2);
spi_send(data3);
// wait tEH (750 ns)
_delay_us(0.75);
// clear CE
LC72131_PORT &= ~LC72131_CE;
}
//------------------------------------------------------------------------------
void lc72131_setup()
{
static prog_uint8_t ref_data[RX_FREQ_STEP_COUNT] = {
LC72131_REF_1K,
LC72131_REF_3K125,
LC72131_REF_5K,
LC72131_REF_6K25,
LC72131_REF_12K5,
LC72131_REF_25K,
};
uint8_t data;
uint16_t divisor, step;
// calculate divisor
step = pgm_read_word(rx_freq_step_value + rx_freq_step);
divisor = (RX_IF_1 - RX_IF_2 - (rx_freq % 50000)) / step;
// pll data
data = LC72131_SNS | LC72131_XS |
pgm_read_byte(ref_data + rx_freq_step);
// send IN1
lc72131_cmd(LC72131_IN1_CMD, divisor, divisor>>8, data);
// calculate band data
data = pgm_read_byte(band_data + rx_mod);
if(rx_unmute) {
data |= LC72131_BAND_UNMUTE;
}
// send IN2
lc72131_cmd(LC72131_IN2_CMD,
data,
0,
LC72131_IFS);
Top
clawson
Level: Moderator, 100k
Joined: 18 Jul 2005
Posts: 104859 View Posts
Location: (using avr-gcc in) Finchingfield, Essex, England
By the look of the .aps and .aws files there this looks like a project for Atmel Studio 4 together with the avr-
gcc C compiler.
https://www.microchip.com/mplab/avr-support/avr-and-sam-downloads-archive
(https://www.microchip.com/mplab/avr-support/avr-and-sam-downloads-archive)
You may think that 4.19 looks like the latest "V 4 " and would be the one to go with but trust me, you will
have an easier life if you get 4.18 instead.
(http://www.nongnu.org/avr-libc/user-manual/FAQ.html)
Top
PS forgot to say that you might, of course, simply want to migrate this to something like Microchip Studio 7
if you want to move things on a bit by 10+ years.
(http://www.nongnu.org/avr-libc/user-manual/FAQ.html)
Top
ki0bk
Level: 10k+ Postman
Joined: 8 Sep 2014
Posts: 10623 View Posts
Location: Over the rainbow
“
rpz3598
(using ATMEGA8A , if it is necessary)?
FF = PI > S.E.T
Top
awneil
Level: 10k+ Postman
Joined: 2 Jul 2005
Posts: 23038 View Posts
Location: Basingstoke, Hampshire, UK
“ ki0bk
the latest AS7
https://www.microchip.com/en-us/development-tools-tools-and-software/microchip-studio-for-avr-and-
sam-devices (https://www.microchip.com/en-us/development-tools-tools-and-software/microchip-studio-
for-avr-and-sam-devices)
Top Tips:
1. How to properly post source code - see: http://www.avrfreaks.net/comment/2153911#comment-2153911
(http://www.avrfreaks.net/comment/2153911#comment-2153911) - also how to properly include images/pictures
2. "Garbage " characters on a serial terminal are (almost?) invariably due to wrong baud rate -
see: https://learn.sparkfun.com/tutorials/serial-communication (https://learn.sparkfun.com/tutorials/serial-
communication)
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed
you expected
4. Difference between a crystal, and a crystal oscillator: http://www.avrfreaks.net/comment/2204401#comment-2204401
(http://www.avrfreaks.net/comment/2204401#comment-2204401)
5. When your question is resolved, mark the solution: http://www.avrfreaks.net/comment/2198746#comment-2198746
(http://www.avrfreaks.net/comment/2198746#comment-2198746)
6. Beginner's "Getting Started " tips: http://www.avrfreaks.net/comment/2079906#comment-2079906
(http://www.avrfreaks.net/comment/2079906#comment-2079906)
Top
Author Posted: 11 Jul 2021 - 04:04 AM Last Updated: 11 Jul 2021 - 02:55 PM #6 0 0
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
//lc72131.h
#define F_CPU 16000000UL
//#include <stdio.h>
//#include <stdlib.h>
//#include <stdbool.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <inttypes.h>
#define DEFAULT_BAND 0
#define DEFAULT_MODE 0
#define FM_STEREO_MODE 0
#define FM_MONO_MODE 1
#define MW_MONO_MODE 2
/*
DVS ;SNS; LSB Divisor setting (N) Actual divisor
1 ;* ; P0 272 to 65535 Twice the value of the setting
0 ; 1 ; P0 272 to 65535 The value of the setting
0 ;0 ; P4 4 to 4095 The value of the setting
uint8_t LC72131_Read ()
{
// read data into the byte from DO of the LC72131 bus to the MCU
uint8_t i, Data=0;
for ( i = 0; i < 8; i++ )
{
LC72131_PORT|=(1<<LC72131_CL);
Data = (Data >> 1);
if ((LC72131_PIN&(1<<LC72131_DO))!=0 ) {Data |=0x80 ; }
LC72131_PORT&= ~(1<<LC72131_CL );
_delay_us(2);
}
return (uint8_t)( Data );
}
LC72131_PORT&=~(1<<LC72131_CE); //CE=0
LC72131_Send(0x29); //send address for IN2 mode
LC72131_PORT|=(1<<LC72131_CE) ; //CE=1
_delay_us(2);
// BO4 BO3 BO2 BO1 IO2 IO1 IOC2 IOC1 Data=1 Bx=1
// IOC2=0-> nIO2 input mode , IOC2=1 -> nIO2 output mode
// IOC1=0-> nIO1 input mode , IOC1=1 -> nIO1 output mode
// IO2=1 -> nIO2=low, IO2=0-> nIO2=Z,
// IO1=1 -> nIO1=low, IO1=0-> nIO1=Z
// BOn=1 -> nBOn=low, BOn=0 -> nBOn=Z
//selectIO2=0,IO1=0, IOC2=0, IOC1=0
// (BO4_BO3_BO2_BO1<<4)|(IO2_IO1_IOC2_IOC1 =0x00)
LC72131_Send( B4_1_IO);
//DZ1_DZ0=10 DZC; 00=DZA, 01=DZB, 10 =DZC, 11 =DZD, DZA < DZB < DZC < DZD
//UL1_UL0=11 0E is extended by 1 to 2 ms
//DOC2...DOC0=000 DO pin state open
//DNC=0
// DZ1_DZ0_UL1_UL0_DOC2_DOC1_DOC0_DNC //0xB2 or B0
LC72131_Send(0xB0);
//TEST2_TEST1_TEST0=000
//IFS=1 (normal) , 0 sensitivity 10...30 mV
//DLC=0 normal, 1=Forced Low
//TBC=0
//GT1_GT0=00 4us ; 01 =8 us; 10 =32 us; 10 =64 us;
// TEST2_TEST1_TEST0_IFS_DLC_TBC_GT1_GT0; 0x00
LC72131_Send(0x10);
LC72131_PORT&=~(1<<LC72131_CE); //CE=0
return;
}
uint32_t LC72131_ReadData(void)
{
}
else
if (band==BAND_AM_HS)
{
//divisor must be from 272 to 65535
divisor=(uint16_t)(Freq+IF1_AM )/FrefAM_HS ;
//DVS=0, SNS=1, AMIN In HS
// fref=1 kHz AM , step 1 kHz
//R3=1,R2=0, R1=1,R0=1, XS=0,CTE=0, DVS=0,SNS=1 , 4.5 MH
RDD=0xB1; //RDD_AM_HS_4k5;
}
else
if (band==BAND_AM_LS)
{
//divisor must be from 4 to 4095
divisor=(uint16_t)(Freq+IF1_AM )/FrefAM_LS ;
divisor=(uint16_t)(divisor<<4); //load LSB from 4 bit ,
//DVS=0, SNS=0, LS AM In
// fref=1 kHz AM , step 1 kHz
//R3=1,R2=0, R1=1,R0=1, XS=0,CTE=0, DVS=0, SNS=0 , 4.5 MHz
RDD=0xB0;//RDD_AM_LS_4k5 ;
//for 0x0091 ->0x0910
//* * * * ;;'1' rev ;;'9' rev ;; '0' rev ;;
//* ; * ; *; *;;1 ;0 ;0 ;0 ;;1 ;0 ; 0 ; 1 ;; 0 ; 0 ; 0 ;0 ;;0; 0 ; - ;-0 ;;0
//P0;P1;P2;P3 ;;P4;P5;P6;P7;;P8;P9;P10;P11;;P12;P13;P14;P15;; SNS ; DVS ; CTE ;XS;
}
LC72131_SendDivToPLL(divisor, RDD );
return;
}
void InitLC72131()
{
// 0x28 -divider (IN1 mode) addr
// 0x29 -control (IN2 mode) addr
// 0x2A - output (OUT mode) addr
// may be in the main program
LC72131_DDR|=(1<<LC72131_CE)|(1<<LC72131_CL)|(1<<LC72131_DI );
LC72131_DDR&=~(1<<LC72131_DO );
LC72131_PORT&=~(1<<LC72131_CE)|(1<<LC72131_CL)|(1<<LC72131_DI );
LC72131_SetBand_Mode(DEFAULT_MODE );
LC72131_SetPLL_Freq(DEFAULT_FREQ, DEFAULT_BAND);
return;
}
/*
DVS=1,SNS=*(0)
FMIn-> [:2] -> [SW count 4 bit]->[12bit counter]->Fvco/N
Fvco/N ->{PD}-> 0E
fref ->{ }
Fvco=fref*(N*2), set divisor N=272...65535 10..160 MHz
DVS=0,SNS=1
AMIn -> [SW count 4 bit]->[12bit counter]->Fvco/N
Fvco/N ->{PD}-> 0E
fref ->{ }
Fvco=fref*N , N= 272 t0 65535
DVS=0,SNS=0
AMIn ->[12bit counter]->Fvco/N
Fvco/N ->{PD}-> 0E
fref ->{ }
The LC72131 inputs and outputs data using the Sanyo CCB (computer control bus) aud
LSI adopts an 8-bit address format CCB.
B0;B1;B2;B3;;A0;A1;A2;A3
0x82
0;0;0;1;;0;1;0;0; ;; SendHighNubble(0x82),SendLowNibble(0x82)
DI:(Address) B0;B1;B2;B3;A0;A1;A2;A3; (first data In)P0;P1...
IN1 mode
DI control
ADDRESS 82 ;; data
rev 8 ; rev 2 ;
0;0;0;1;0;1;0;0;;P0;P1;P2;P3;;P4;P5;P6;P7;;P8;P9;P10;P11;;P12;P13;P14;P15;; SNS ;
SendNibble(HighNibble(0x82)) ; SendNibble(LowNibble(0x82))
SendNibble(P3_P0) ; SendNibble(P7_P4) //P7...P0
SendNibble(P11_P8) ; SendNibble(P15_P12)
SendNibble(XS_CTE_DVS_SNS); SendNibble(R3_R2_R1_R0)
or
SendByte(0x28);
SendByte(P7_P0); //Lowbyte(divisor), for example divisor=0x07DE
SendByte(P15_P8);//Highbyte(divisor)
SendByte(R3_R2_R1_R0_XS_CTE_DVS_SNS);
IN2 mode
DI control
ADDRESS 92 ;; data
rev 9 ; rev 2 ;
1;0;0;1;0;1;0;0;;IOC1;IOC2;IO1;IO2;;BO1;BO2;BO3;BO4;;DNC;DOC0;DOC1;DOC2;;UL0;UL1;D
or
SendByte(0x29);
SendByte((BO4_BO3_BO2_BO1<<4)|IO2_IO1_IOC2_IOC1 );
SendByte(DZ1_DZ0_UL1_UL0_DOC2_DOC1_DOC0_DNC);
SendByte(TEST2_TEST1_TEST0_IFS_DLC_TBC_GT1_GT0);
OUT Mode
DI control
ADDRESS A2
A rev 2 Rev
0;1;0;1; 0;1;0;0; ;
DO answer
I2;I1;0; UL; C19;C18;C17;C16;;C15;C14;C13;C12;;C11;C10;C9;C8;;C7;C6;C5;C4;;C3;C2;C
uint32_t data=(DATA2<<16)|(DATA1<<8)|DATA0 ;
1)
divisor=(100700/2)/25kHz=2014=07DE hex
step=2*fref=2*25=50 kHz
reverse bits
'E' rev ;; 'D' rev ;;'7' rev ;; '0' rev ;;
0 ; 1 ; 1; 1;;1 ;0 ;1 ;1 ;;1 ;1 ; 1 ; 0 ;; 0 ; 0 ; 0 ;0 ;;* ; 1 ; - ;-0 ;;
P0;P1;P2;P3 ;;P4;P5;P6;P7;;P8;P9;P10;P11;;P12;P13;P14;P15;; SNS ; DVS ; CTE ;XS;;R
2)
SW, 5 kHz steps(DVS=0,SNS=1,AMIN HS selected )
step= fref= 5 kHz
SW RF=27.75 MHz ,IF=+450 kHz
SW VCO=22.20 MHz
PLL fref=5 kHz , R0=0,R1=14,R2=0,R3=1
divisor=22200kHz/5kHz=4440=1158 hex
reverse bits
'8' rev ;; '5' rev ;;'1' rev ;; '1' rev ;;
0 ; 0 ; 0; 1;;1 ;0 ;1 ;0 ;;1 ;0 ; 0 ; 0 ;; 1 ; 0 ; 0 ;0 ;;1 ; 0 ; - ;-0 ;;0 ;
P0;P1;P2;P3 ;;P4;P5;P6;P7;;P8;P9;P10;P11;;P12;P13;P14;P15;; SNS ; DVS ; CTE ;XS;;R
3)
MW,10 kHz steps(DVS=0,SNS=0,AMIN LS selected )
step= fref= 10 kHz
SW RF=1000 kHz ,IF=+450 kHz
SW VCO=1450 kHz
PLL fref=10 kHz , R0=0,R1=0,R2=0,R3=1
divisor=1450kHz/10kHz(fref)=145=0091 hex
divisor=divisor<<4;
*/
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
I use only nBO4, nBO3,nBO2 (nBO1 and other GPIO pins are reserved, not used in my circuit ) , FMIn, AMI,
CE,DI,CL.
nBO4 - stereo (0- on , for p-n-p transistor , emitter to Vcc , 10..22 k resistor base to nBO4, collector to the
circuit with LED and resistor 1 k (TA7343AP) ),
nBO3 - FM tuner (0 -on , for p-n-p transistor to Vcc with 10...22 k resistor (base-> nBO3) ),
nBO2 - FM tuner (0 -on , for p-n-p transistor , emitter to Vcc with 10...22 k resistor (base-> nBO1) )
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
Pins:
PD0 btn0 (to GND)
PD1 btn1 (to GND)
PD2 btn2 (to GND)
*/
#define Ndigits 6
uint32_t Freq=Freq_default;
uint8_t DisplayBuffer[6];
uint8_t Comma;
uint8_t Pos=3;
uint8_t BTNS=0;
/*
ISR(TIMER0_OVF_vect)
//interrupt[TIM0_OVF] void timer0_ovf_isr(void)
{
LedSend();
return;
}
*/
return EEDR;
}
void Data_Decoding(void)
{
asm( "cli ");
Comma = 2;
void PrintFreq()
{
LCDsendCommand( 0x80);
for(i=0;i<6;i++)
{
//if (i==Comma) {LCDsendCommand( 0x80+i+1); LCDsendChar('.');}
LCDsendChar(DisplayBuffer[i]);
}
LCDsendChar('k');
LCDsendChar('H');
LCDsendChar('z');
LCDsendCommand( 0x80+Pos);
LCDsendCommand(0x0E) ;
}
LCD_init();
LCD_cursor(0);
return;
}
/*
void Timer0_Init( void )
{
TCCR0A = 0b00000000;
TCCR0B = 0b00000011; //clkI/O/ 64 (From prescaler)
TCNT0 = 0b00000000;
TIMSK = 0b00000010; // Разрешено прерывание по переполнению
return;
}
*/
void SaveToMemory(void)
{
asm( "cli ");
EEPROM_write(0,DisplayBuffer[0]); //1
EEPROM_write(1,DisplayBuffer[1]); //0
EEPROM_write(2,DisplayBuffer[2]); //3
EEPROM_write(3,DisplayBuffer[3]); //7
EEPROM_write(4,DisplayBuffer[4]); //0
EEPROM_write(5,DisplayBuffer[5]); //0
_delay_ms(1000);
}
void ReadMemory(void)
{
if((Freq>Freq_max)||(Freq<Freq_min)) { Freq=Freq_default;}
_delay_ms(300);
return;
}
switch(Pos)
{
case 0:
DivStep=100000; //x03.700
break;
case 1:
DivStep=10000; //1x3.700
break;
case 2:
DivStep=1000; //10x.700
break;
case 3:
DivStep=100; //103.x00
break;
case 4: //103.7x0
DivStep=10;
case 5: //103.70x
DivStep=Freq_Step;
return;
}
void CursorRight()
{
asm( "cli ");
if(Pos>1) {Pos--;}
DecodeCurPos(Pos);
PrintFreq();
_delay_ms(800);
return;
}
void CursorLeft(void)
{
asm( "cli ");
if(Pos<Ndigits-1) {Pos++;}
DecodeCurPos(Pos);
PrintFreq();
_delay_ms(800);
return;
}
void IncFreq(void)
{
Freq +=DivStep;
Data_Decoding();
LC72131_SetPLL_Freq(Freq,BAND_FM );
PrintFreq();
_delay_ms(300);
return;
}
void DecFreq(void)
{
Freq-=DivStep;
if(Freq <Freq_min) { Freq= Freq_max; }
Data_Decoding();
LC72131_SetPLL_Freq(Freq, BAND_FM );
PrintFreq();
_delay_ms(300);
return;
}
void Control(void)
{
BTNS= ((~(PINC))&0b00011100) ;
switch(BTNS)
{
case BTN_READ:
ReadMemory();
break;
case BTN_SAVE:
SaveToMemory();
break;
case BTN_INCTEP:
CursorLeft();
break;
case BTN_DECSTEP:
CursorRight();
break;
case BTN_INCF:
IncFreq();
break;
case BTN_DECF:
DecFreq();
break;
default:
break;
}
//asm( "sei ");
return;
}
int main(void)
{
InitPorts( );
InitLC72131();
LC72131_SetBand_Mode(FM_STEREO_MODE);
Comma = 2;
DecodeCurPos(Pos);
Freq=Freq_default;
ReadMemory();
LC72131_SetPLL_Freq(Freq,BAND_FM );
Data_Decoding();
PrintFreq();
//Timer0_Init();
while(1)
{
Control();
}
}
//lcd.h
//*****************************************************************************
//fix some bugs with initialising and delays
//******************************************
#define LCD_4bit
//***********************************************
#define LDP PORTB //define MCU port connected to LCD data pins
#define LCP PORTB //define MCU port connected to LCD control pins
#define LDDR DDRB //define MCU direction register for port connected to LCD
#define LCDR DDRB //define MCU direction register for port connected to LCD
/*******************************************/
void lcd_enable(void)
{
LCP |= (1<<LCD_E );
_delay_us(40);
LCP &= ~(1<<LCD_E );
_delay_us(40);
}
/*
Power on
3)
Wait for more than 100 µs
RS ; R/nW ;DB7 ;DB6; DB5; DB4
0 ; 0 ; 0 ; 0 ; 1 ; 1
7)
RS ; R/nW ;DB7 ;DB6; DB5; DB4
0 ; 0 ; 0 ; 0 ; 1 ; 0
0 ; 0 ; 0 ; 0 ; 1 ; 0
0 ; 0 ; N ; F ; * ; *
0 ; 0 ; 0 ; 0 ; 0 ; 0
0 ; 0 ; 1 ; 0 ; 0 ; 0
0 ; 0 ; 0 ; 0 ; 0 ; 0
0 ; 0 ; 0 ; 0 ; 0 ; 1
0 ; 0 ; 0 ; 0 ; 0 ; 0
0 ; 0 ; 0 ; 1 ; I/D ; S
*/
;ENTRY_... - sets entry mode, S = display shift on, INC / DEC cursor move dir
.equ ENTRY_DEC = 0x04
.equ ENTRY_DEC_S = 0x05
.equ ENTRY_INC = 0x06
.equ ENTRY_INC_S = 0x07
;
.equ CURS_RGT = 0x93
.equ DD_RAM_ADDR = 0x80 ; Least Significant 7-bit are for address
.equ DD_RAM_UL = 0x80 ; Upper Left coner of the Display
;
;
;
;*******************************************************************
;* The LCD Module Subroutines *
;*******************************************************************
;
;*******************************************************************
;LCD Wait
;*******************************************************************
;LCDWait1: nop
; nop
; nop
; nop
; nop
; nop
; ret
ret
lcd_delay1ms:
ldi r26, 21
ldi r27, 196
L1_1ms:
dec r27
brne L1_1ms
dec r26
brne L1_1ms
ret
lcd_delay5ms:
lcd_delay20ms:
rcall lcd_delay5ms
rcall lcd_delay5ms
rcall lcd_delay5ms
rcall lcd_delay5ms
ret
lcd_delay50ms:
rcall lcd_delay20ms
rcall lcd_delay20ms
rcall lcd_delay5ms
rcall lcd_delay5ms
ret
lcd_delay_loop:
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
rcall lcd_delay50ms
ret
;*******************************************************************
;* This routine checks the busy flag, returns when not busy *
;*******************************************************************
;LCDBusy_Check:
; rcall LCDWait
LCD_Enable:
sbi LCDOUT, E ; toggle E for LCD
rcall LCDWait40us
cbi LCDOUT, E
rcall LCDWait40us
ret
;*******************************************************************
;*LCDSendChar - Sends character to LCD *
;*This routine splits the character into the upper and lower *
;*nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
LCDSend_Char:
; rcall LCDBusy_Check ; Wait for LCD to be ready
;rcall LCDWait40us
mov r29, W
swap r29 ; D7-D4 -> PD3-PD0, PD4-PD7 =0
andi r29, 0x0f; Get upper nibble into upper half port
;ori r29, 0x10
out LCDOUT, r29 ; Send data to LCD ; already set LCD to write in busy routin
sbi LCDOUT,RS
rcall LCD_Enable ; saving space - sod readability thou
mov r29, W
andi r29, 0x0f ; Get lower nibble into upper half port
;ori r29,0x10 ; (1<<RS)
out LCDOUT, r29 ; Send data to LCD
sbi LCDOUT, RS ; Set LCD to data mode
rcall LCD_Enable;
cbi LCDOUT,RS
ret
;*******************************************************************
;* SEND_CMD - Sends command to LCD *
;* This routine splits the command into the upper and lower *
;* nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
LCDSend_Cmd:
;rcall LCDBusy_Check ; Wait for LCD to be ready
; rcall LCDWait40us
cbi LCDOUT,RS
mov r29, W
swap r29 ; D7-D4 -> PD3-PD0, PD4-PD7 =0
andi r29, 0x0F ; Get upper nibble into upper half port ; LCDREG1= W & 0xf0
out LCDOUT, r29 ; Send data to LCD ; already set LCD to write and ctl ;
rcall LCD_Enable ; saving space - sod readability thou
mov r29, W
andi r29, 0x0F ; Get lower nibble into upper half port
out LCDOUT, r29 ; Send data to LCD ; already set LCD to read in busy routine
rjmp LCD_Enable
ret
;*************************************************************************
;Display routines
;*************************************************************************
LCDdisplay_init:
clr W
out LCDOUT,W
ldi W, 0b00111111;
out LCDTRIS ,W
rcall lcd_delay50ms ;1) power on , delay>50 ms
ldi W,0x03
out LCDOUT, W ;Init LCD
rcall LCD_Enable; ; 2) RS=0, RnW=0 data= 0x03 , then delay >4.1 ms
rcall lcd_delay5ms
rcall LCD_Enable; ; 3) RS=0, RnW=0 data= 0x03 , then delay > 100 us
rcall lcd_delay1ms
rcall LCD_Enable; ;4) RS=0, RnW=0 data= 0x03 , then delay > 100 us
rcall lcd_delay1ms
;in the 8 bit mode
ldi W,0x02 ;5) RS=0, RnW=0 data= 0x02 , then del
out LCDOUT, W
rcall LCD_Enable;
rcall lcd_delay1ms
ldi W, 0x01
rcall LCDSend_Cmd ; clear display then wait >3 ms or check BF
rcall lcd_delay5ms
ldi W, 0x0C
rcall LCDSend_Cmd ; display on
ldi W,0x06
rcall LCDSend_Cmd ; input mode Auto Increment cursor
; ldi W,0x0E
; rcall LCDSend_Cmd ;
ldi W,0x02
rcall LCDSend_Cmd ; Cursor at home position
rcall lcd_delay5ms
ret
LCDClear_Display:
ldi W, 0x01
rcall LCDSend_Cmd ; clear display then wait >3 ms or check BF
rcall lcd_delay5ms
ret
Top
fix
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
Fixed bug with EEPROM ( problem with data encoding and loading in the Data_Decoding(),
ReadMemory()and PrintFreq() ). Fixed bug with multiplying .
void Data_Decoding(void)
{
asm( "cli ");
LCDsendCommand( 0x80+Pos);
LCDsendCommand(0x0E) ;
}
...
void ReadMemory(void)
{
if((Freq>Freq_max)||(Freq<Freq_min)) { Freq=Freq_default;}
_delay_ms(300);
return;
}
Top
Author Posted: 17 Jul 2021 - 09:55 AM #12 0 0
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
Test edition (ATMEGA8A, 16 MHz , 1602A, RDS(0A,0B,2A,2B, PI), AM, FM for LA1787+TA7343AP(6V) ). Check
and fix some bugs, rewrite some subroutines ( not very fast works with RDS ). Change some values for your
tuner .
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
My alternative edition with group type autoselecting (0a/0b , 2a/2b) . Works if bit error ratio in the
decoder is good .
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
An edition with one cursor button and mode switch button, one memory location . But you can create
more than one memory cell for 0x2000+ 0x000...0x1FF, add SSB mode (using nBO1 for SSB oscillator 450
kHz control for band 160 m , for example ) .
Top
My version for WinAVR , ATMEGA8A-16PU(-PU), 16 MHz osc., FM 64-110 MHz (IF=10.7 MHz), AM/SSB 100
kHz-4MHz (IF1=10.71 MHz, IF2=450 kHz , fixed Losc=10 uH ->8.2uH approx. for 4 MHz (fosc= 14.71 MHz ,
Vt=7.8 V) , and for 100 kHz (fosc=10.81 MHz, Vt=0.5..0.8 V) ), using LA1787,TA7343AP, SSB osc. 450 kHz
(nBO4 ) .
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
A new version with alternative band switch for FM/AM/SSB and with encoder
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
My modules (for example, for test Fmax of the LC72131 and LM7001 , but for other toools, for example for
AM/FM probe tool ) with examples of the modules with some SIO control methods (may be not ready, with
bugs ).
Top
A counter, ROM and a switch in te circuit are for encoder signals emulating(only for the emulator, connect
the rotary encoder to the PD0,PD1,GND with two pull-up resistors)..
Top
rpz3598
Level: Hangaround
Joined: 24 Nov 2017
Posts: 249 View Posts
A PLL probe device with ATMEGA8A, LC72131 +band decoder , VCOs, divider by10, LF oscillator and amplifier
. It is possible to add the frequency sweep mode with step option.
Top
Cookies (https://www.microchip.com/en-us/about/legal-information/microchip-cookie-statement)