atmega32 interfacing taking user input from keypad - user-input

Hi I am a newborn person to this AVR coding world .
I am developing a 4*4 keypad to take user inputs and to display some of the things in the 16*2 LCD display.
So please u guys as experts I request your suggestions and explanations of such these points.
I kindly request your help on,
I can't understand the following code parts,
#define D5 eS_PORTD5 -
DDRD = 0xFF;
DDRB = 0x0F;
is this code fragment is used a predefined function , if so what is that,
if(bit_is_set (PINB,6))
the full code of this is attached herewith.
thank you for your kindness to waste your time on reading this , please help for a beginner if you know evenone of these things.

DDRD = 0xFF sets all bits of register DDRB to 1 which is setting the port D as outputs
(1 = output, 0 = input)
DDRB = 0x0F is setting portb low 4 bits as output, upper 4 bits as outputs.
bit_is_set a #define from sfr_defs.h, in this case, it checks if bit 6 is set from the PINB port.
it is the equivalent of (PINB & (1<<6))

Related

Intepretation of output from register. AT90E32 + stm32

i have a problem with documentation, which i don't understand. Documentation is here:
Read sequence is on the page 31.
I want to read Phase C voltage RMS.
From this register i get in that order: 0011110010001111.
Value read should be 233.3V.
I am beginner and really don't know hot to interpret this. When i read first byte from right 11110001 that is 241. The next byte read from left is: 00111100 which is 60, but when i multiply this by 0.01V (in documentation is that 1LSB should be multiply'ed by 0.01 - what means 1LSB? ) i get 241,6 V. That is correct? Thanks for any help guys.

UART serial interface

I want to transfer 8 bits serially (1 bit/clock cycle) through a 1 bit serial interface of a UART. I created an 8 bit packet in the transaction class and drove the packet through the driver modport of the interface. Here is the code snippet below.
for (i = ($size(pkt.RXD)-1); i <= 0; i = i-1) begin
RXSD_vif.DRV.cb_RXSD_DRV.RXD <= RXSD_pkt[i];
end
RXSD_vif is the virtual interface handle.
DRV - modport
cb_RXSD_DRV is the clocking block where I'm taking the positive clock edge with RXD made out to be output.
I'm getting a compile error saying "Too many indices going into RXSD_pkt".
I'm fairly new to this and would appreciate any help in telling me how to fix this. Thanks in advance
I think you're passing the index 'i' to the handle of the packet class. There should be an 8 bit vector within the class through which you need to index. Does this help in any way?

how to solve something associated with memory and speed of my computer?

first of all , i have a specific task that works at the expense of every possible combination of range , i already used a program that perform my purpose this code is :
clc
clear
a = input('Please, select your array: ')
b = a(:).'
c = length(b)
for d =1:c
if (d<c)
e{d} = nchoosek(b, d);
end
end
tt=cellfun(#(m) padarray(m,[0 max(cellfun(#(n) size(n,2), e)) - size(m,2)],'post'), e,'UniformOutput',0);
uu=cell2mat(tt([1:d-1])')
suu=size(uu)
uu(:,((suu(2))+1))=sum(uu')'
but i faced a big problem during the implementation of the program that this command :
e{d} = nchoosek(b, d)
has failed to continue as result of the number of possible choices and number of selected choices and finally the limitations:
When b = nchoosek(n,k) is sufficiently large, nchoosek displays a warning that the result might not be exact. In this case, the result is only accurate to 15 digits for double-precision inputs, or 8 digits for single-precision inputs.
C = nchoosek(v,k) is only practical for situations where length(v) is less than about 15.
that's where my vector consist of the hundreds of numbers which i want to do this process on.
when i run the program , then matlab is being busy until giving me out of memory error in a time and takes along time without implementation of the program then i am forced to out of the program . i looked for a solution by help "out of memory" but i failed to find any solution then i tried to use another command that's
combnk(v,k)
but it takes along time without implementation of the program then i am forced to out of the program too
please please please , i want to practical solution to perform a lot of processes like this for my work .
If the solution depends on the capabilities of my computer tell me about that computer specifications which performs this program easily , quickly and immediately
note that my computer specifications are :
win 7
64 bit
4 GB RAM
2.3 cpu i3

How does Matlab determine size of BytesAvailable for Serial Connection?

How does Matlab determine the value of the BytesAvailable which is used in the tmtool for serial connection?
I have to send, say 512 bytes from my Matlab to my device over UART. The problem is only 96 bytes are sent to my device. i don't understand what happened to my remaining bytes! FYI: The value of BytesAvailableFcnCount being shown now is 48. On checking here, I found that the default value is 48. So I increased it to 512; but the same issue recurred. I have BytesAvailable being shown still 95!
Please suggest me some way. I have pasted the code in which I am trying to do this:
fopen(obj1); //obj1 is the name of my serial object
A = fopen('Path of the file I am using');
txdata = fread(A,[5 100],'uint8','ieee-be');
[my_count_rows, my_count_columns]=size(txdata);
for my_i = 1:my_count_columns
for jjj = 1:my_count_rows
fwrite(obj1,txdata(jjj,my_i),'uint8');
end
end

Data reading in Fortran

EDIT: I am Making this just a question about the Fortran and will start a new question about converting to MATLAB.
ORIGINAL:
I am working on a project and am trying to port some old Fortran code into Matlab. I have almost no Fortran experience so I am not quite sure what is going on in the following code. The Fortran code is simply for interpreting data from a binary file and I have made some decent progress at porting stuff into MATLAB but have got stuck at the following part:
IMPLICIT NONE
DOUBLE PRECISION SCALE
CHARACTER*72 BLINE
CHARACTER*72 DATA_FILE_FULL_NAME
CHARACTER*6 DATA_FILE_NAME
CHARACTER*4 CH4, CH4F
REAL*4 RL4
EQUIVALENCE (RL4,CH4)
CHARACTER*2 C2
LOGICAL LFLAG
c2='69'
LFLAG=.TRUE.
DATA_FILE_FULL_NAME='./'//DATA_FILE_NAME//'.DAT'
OPEN(UNIT=20, FILE=DATA_FILE_FULL_NAME, ACCESS='DIRECT',
. RECL=72, status='OLD')
READ(20,REC=1) BLINE
CH4f=BLINE(7:10)
call flip(4,lflag,ch4f,ch4)
SCALE=RL4
RETURN
END
c ..................................................
subroutine flip(n,lflag,ch1,ch2)
c ..................................................
integer*4 n, i
character*(*) ch1, ch2
logical lflag
if(lflag) then
do i=1,n
ch2(i:i)=ch1(n-i+1:n-i+1)
enddo
else
ch2=ch1
endif
return
end
What I am stuck with is getting the correct value for SCALE because I am not exactly sure what is happening with the RL4. Can someone explain to me why RL4 changes value and what process changes it so that I can put this process into MATLAB?
The code probably does change of Endianness - the byte swap. The equivalence means that the equivalenced variables share the memory and you can treat the 4 bytes read from the file as a number after the byte swap.
The four bytes are therefore interpreted as a four byte real RL4 and converted to a double precision value scale after that.
The byte swap is done only when the logical lflag is true. That will probably be when the byte order of the file is not the same as the machine native byte order.
In Matlab you can probably use http://www.mathworks.com/help/matlab/ref/swapbytes.html .
Just read the 4 byte floating point number and swap the bytes if necessary.