PART 1: Let me start to answer the none-display questions.
1010,0000 = 160 decimal, is my interpretation right in this way?
In C and C++ (which is the programming language used by Arduinos), all numbers are decimal unless they are prefixed with 0 (zero) or 0x (zero x).
If a number has an initial zero, then the number is interpreted as octal number. This means that "010" has the value 8!
If a number has an initial prefix of "0x" then the number is interpreted as hexadezimal value.
Actually i try to avoid octal numbers, but hexadezimal number are quite useful to send to a display controller.
So, 1010,0000 can be written as 0xa0 (or 0xA0) because four bits equal exactly one hexadecimal digit:
binary 1010 = hex a
binary 0000 = hex 0
1. Should SPI.transfer ( ) only tranfers decimal number or how to write it to send other types of data?
SPI.transfer can transfer a value between 0 and 255. The range is important, but not the representation of the number.
It does not matter if you write SPI.transfer(160) or SPI.transfer(0xa0). In both cases a specific sequence of 8 bits is transfered.
You could also transfer a single letter: SPI.transfer('B') which is equal to SPI.transfer(66).
3. Should all arduino sketches need a loop () function? what if I only want the program run for once? for display how to do it?
let me split this into three questions:
> Should all arduino sketches need a loop () function?
Yes. I leave it as an excercise to you to try to compile without "loop()"
> what if I only want the program run for once?
Put all your code into setup().
Microcontroller do have the ability to go to some shutdown mode in order to reduce power consumtion to a minimum, but i think this is beyond the scope of this thread.
> for display how to do it?
Do what? If you just want to display something static until power is switched of, then put all your init and display code into "setup()". But for my own applications it is more like this:
output something to the user
wait for some input
// loop will start at the beginning and wait for some input again
If the input is a temperature sensor, then this could look like this:
read temperature from sensor
delay for 1 second
This wil update the display every second.
PART 2: Display specifc answers
First, i think you understood the concept of communication with the display controller. The code looks quite good regarding the setting of the command/data and the chip select line.
2. How to set the display column address ( -Y ) see ic spec P13 , command as blow , how to pick a specific column of pixels?
Quick answer: Either the display vendor tells you this or you have to figure this out by testing and analysis.
For the display Chip on Glas module on your picture, probably three or four companies are involved:
Company 1: Creates the actual liquid crystal
Company 2: Creates the display controller (UC1705)
Optional Company B: Creates LED backlight
Company 3: Assembles the liquid crystal, the optional backlight and the display controller to something which is called COG Module.
The problem is: We do not know how company 3 has connected the display controller with the liquid crystal. For example:
The controller actually has 132x65 dots, but the liquid crystal only has 128x64. Which line and which colums are invisible? This is a decision that was taken by company 3 during the wiring of the two subcomponents.
Let as consider the binary value 1000,0000 at position 0 in the controller ram.
Upper left pixel of the 128x64 might be swithed on. But it might also be the lower left corner.
Also it might be the 7th pixel of the display on the top row if the byte order is swapped.
It might also be invisible if the liquid crystal if the crystal is connected to rows 1 to 65.
It might also be invisible if the liquid crystal is connected to colums 4 to 132.
But there might be also a pixel visible at position 3 if the lc is connected from 4 to 132 and the byte order is swapped.
This means: If company 3 does not provide you enough information, then you have to set some pixel on the screen do some reverse engineering how the interconnection between controller and crystal.
There are also several registers in the controller which allow you to setup the controller so that some parts of the swapping is done automatically (like SEG and COL direction).
This is my suggested procedure on an unknown LCD:
Step 1: Try to make something visible. This includes
- Activate charge pump
- Activate Display
- Activate "all pixel on" mode or write some random pixels in the middle of the display
- setup display contrast
- activate other LCD parameters
Step 2: Fine tuning
- Figure out bit order
- Analyse how the 128x64 is mapped to the 132x65 RAM area
- Apply correct COM and SEG order
Of course a good datasheet from company 3 will tell you all these details
So my question: Do you see something on the screen already?